2013-03-14 25 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

我得到了答案,我应该检查更多的会议。我忘了编码它。