开发者

http post request not sending parameters in Blackberry 5.0

I've been working on a BlackBerry post request, and the request is getting sent, but the parameters don't seem to be. Here is my code:

        HttpConnection httpConnection = (HttpConnection) Connector.open(url);
        httpConnection.setRequestMethod(HttpConnection.POST);
        httpConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

        URLEncodedPostData encPostData = new URLEncodedPostData("UTF-8", false);
        encPostData.append("time", "1314144000");

        System.out.println("url: " + httpConnection.getURL());

        byte[] postData = encPostData.toString().getBytes("UTF-8");

        System.out.println("post d开发者_Go百科ata:  " + encPostData.toString());
        httpConnection.setRequestProperty("Content-length", String.valueOf(postData.length));

        System.out.println("url: " + httpConnection.getURL());
        System.out.println("message:" + httpConnection.getResponseMessage());

        OutputStream os = httpConnection.openOutputStream();
        os.write(postData);
        os.flush();
        os.close();

The response I get from the server(which we set up) is that we didn't send a time stamp. Is there something wrong with my

encPostData.append("time", "1314144000");

code?


Your call to getResponseMessage() before writing the post data is forcing a response before anything has been written on the connection.

System.out.println("message:" + httpConnection.getResponseMessage());

Move that to the end, after the output stream data has been written, and I think it will work better for you.


Make the http connection in read write mode.Might be that is the problem making http connection without mode link

HttpConnection connection = (HttpConnection) Connector.open("url", Connector.READ_WRITE);

See below link for making http connection. blackberry server connection problem

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜