我一直在处理BlackBerry发布请求,请求已发送,但参数似乎不是。这是我的代码:
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 data: " + 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();
我从服务器(我们设置)获得的响应是我们没有发送时间戳。我的
有问题吗?encPostData.append("time", "1314144000");
码
答案 0 :(得分:5)
在写入数据之前调用getResponseMessage()会在连接上写入任何内容之前强制响应。
System.out.println("message:" + httpConnection.getResponseMessage());
在输出流数据写完后,将它移到最后,我认为它会更适合你。
答案 1 :(得分:0)
在读写模式下建立http连接。可能是在没有模式链接的情况下进行http连接的问题
HttpConnection connection = (HttpConnection) Connector.open("url", Connector.READ_WRITE);
请参阅以下链接进行http连接。 blackberry server connection problem