2013-03-14 9 views
0

REST API를 통해 서버에 연결할 수있는 Nokia SDK 2.0 (J2ME)을 사용하는 S40 용 앱을 개발 중입니다.J2ME의 HTTPConnection POST 403 오류입니다. Nokia

그러나 일부 API (POST 메서드 사용) 결과 403 번 - 금지되었습니다. apigee 사이트에서 동일한 헤더와 본문을 사용하여 API를 확인한 결과 놀라 울 정도로 성공했습니다 (200 OK 응답). 불행히도 고객의 기밀로 인해 URL을 공유 할 수 없습니다.

하지만 난이 기능을 사용하고 있습니다 :

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 본문의 일부는 쿠키는 POST 헤더의 일부입니다. 그리고 항상 403 오류가 발생합니다.

코드를 apigee (웹) 및 내 앱 (j2me 앱)에서 서로 다른 응답으로 만들 수있는 가능성은 있습니까? 그렇다면 어떻게 해결할 수 있습니까?

도움을 주셔서 감사합니다. :)

답변

0

답변을 얻었으므로 세션에서 더 확인 했어야합니다. 나는 그것을 인코딩하는 것을 잊었다.