HTTPConnection 对象不返回任何内容
我正在尝试通过 Blackberry 中的 HttpConnection 将一些值发布到服务器。我认为我更接近我正在尝试的解决方案。但是一旦我建立连接并使用方法 getResponseCode()。它没有给我带来任何回报。我也尝试过调试选项。但我无法找到什么是回报。在该语句出现之前,控制会顺利进行。一旦到达该特定语句,它甚至就会退出调试模式。以下是我附上的片段,请也让我知道您的建议。
// MyHttpConnectionService.java
........
........
........
OutputStream _outputStream = _connection.openOutputStream();
try {
int rc = _connection.getResponseCode(); // My control is getting lost here
System.out.println("Response Code :" + rc);
System.out.println("Response Code :" + rc + " if HTTP OK :"
+ (rc == HttpConnection.HTTP_OK));
.........
.........
}catch(Exception e){
e.printStackTrace();
}
它也不会抛出任何异常。
任何帮助表示赞赏。
I am trying to post some values to the server through HttpConnection in Blackberry. I think i am closer to the solution that i am trying for. but once i establish the connection and used the method getResponseCode(). it returns me nothing. i tried with debug option too. but i can't able to find what is returns. the control goes smoothly until that statement. Once that particular statement is reached, then it comes out of the debug mode even. below is the snippet i have attached with, Please let me know your suggestions too.
// MyHttpConnectionService.java
........
........
........
OutputStream _outputStream = _connection.openOutputStream();
try {
int rc = _connection.getResponseCode(); // My control is getting lost here
System.out.println("Response Code :" + rc);
System.out.println("Response Code :" + rc + " if HTTP OK :"
+ (rc == HttpConnection.HTTP_OK));
.........
.........
}catch(Exception e){
e.printStackTrace();
}
It doesn't throws any exception too.
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 HTTPConnection 文档,我认为你应该将你的值写入
_outputStream
,然后调用outputStream.flush()
。您提到调用
_connection.getResposeCode()
时失去控制,我认为这是因为此方法做了几件事。从示例源代码中的注释来看:如果到达服务器时出现问题,可能与您的连接字符串有关。您是否正确设置了连接字符串?
Looking at the documentation for HTTPConnection, I think you should write your values to
_outputStream
and then calloutputStream.flush()
.You mention control being lost when calling
_connection.getResposeCode()
, I think that is because this method does several things. From the comments in the example source code:If there are problems reaching the server, it may have to do with your connection string. Are you setting up your connection string correctly?