0

我正在使用可以通过 REST API 连接到服务器的诺基亚 SDK 2.0 (J2ME) 为 S40 开发应用程序。

但是有一些 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 正文的一部分,cookie 是 POST 标头的一部分。它总是导致 403 错误。

是否有可能使代码在 apigee(网络)和我的应用程序(j2me 应用程序)上产生不同的响应?如果是这样,如何解决这个问题?

将不胜感激任何帮助。:)

4

1 回答 1

0

我得到了答案,我应该在会议上检查更多。我忘记编码了。

于 2013-03-22T22:17:22.133 回答