2013-03-14 26 views
0

我正在使用諾基亞SDK 2.0(J2ME)開發適用於S40的應用程序,它可以通過REST API連接到服務器。J2ME中的HTTPConnection POST中的錯誤403 Nokia S40

但是有一些API(使用方法POST)導致錯誤403 - 禁止。我已經在apigee站點檢查了API,頭部和身體完全相同,結果令人驚訝地成功(200 OK響應)。很遺憾,由於我的客戶機密,我無法分享網址。

但我使用這個功能:

public static String sendHTTPPOST(String url, String parameter, String cookie) { 
    HttpConnection httpConnection = null; 
    DataInputStream dis = null; 
    DataOutputStream dos = null; 
    StringBuffer responseMessage = new StringBuffer(); 
    try { 
     httpConnection = (HttpConnection) Connector.open(url, Connector.READ_WRITE); 
     httpConnection.setRequestMethod(HttpConnection.POST); 
     httpConnection.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Configuration/CLDC-1.0"); 
     httpConnection.setRequestProperty("Content-Type", "application/json"); 
    httpConnection.setRequestProperty("Cookie", "eid="+cookie); 
     httpConnection.setRequestProperty("Content-length", "" + parameter.getBytes().length); 

     dos = httpConnection.openDataOutputStream(); 
     byte[] request_body = parameter.getBytes(); 
     for (int i = 0; i < request_body.length; i++) { 
      dos.writeByte(request_body[i]); 
     } 

     dos.flush(); 

    dis = new DataInputStream(httpConnection.openInputStream()); 
     int ch; 
     while ((ch = dis.read()) != -1) { 
      responseMessage.append((char) ch); 
     } 
    } catch (Exception e) { 
     e.printStackTrace(); 
     responseMessage.append("ERROR"); 
    } finally { 
     try { 
      if (httpConnection != null) { 
       httpConnection.close(); 
      } 
      if (dis != null) { 
       dis.close(); 
      } 
      if (dos != null) { 
       dos.close(); 
      } 
     } catch (IOException ioe) { 
      ioe.printStackTrace(); 
     } 
    } 
    return responseMessage.toString(); 
} 

的參數是POST身體的一部分,該cookie是POST頭的一部分。 它總是導致403錯誤。

是否有任何可能使代碼在apigee(web)和我的應用程序(j2me應用程序)上產生不同的響應? 如果是這樣,該如何解決?

將不勝感激任何幫助。 :)

回答

0

我得到了答案,我應該檢查更多的會議。我忘了編碼它。