HTTPConnection 对象不返回任何内容

发布于 2024-11-04 18:07:55 字数 752 浏览 2 评论 0原文

我正在尝试通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

衣神在巴黎 2024-11-11 18:07:55

查看 HTTPConnection 文档,我认为你应该将你的值写入_outputStream,然后调用outputStream.flush()

您提到调用 _connection.getResposeCode() 时失去控制,我认为这是因为此方法做了几件事。从示例源代码中的注释来看:

获取响应代码将打开连接、发送请求并读取 HTTP 响应标头。标头将被存储直到请求为止。

如果到达服务器时出现问题,可能与您的连接字符串有关。您是否正确设置了连接字符串?

Looking at the documentation for HTTPConnection, I think you should write your values to _outputStream and then call outputStream.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:

Getting the response code will open the connection, send the request, and read the HTTP response headers. The headers are stored until requested.

If there are problems reaching the server, it may have to do with your connection string. Are you setting up your connection string correctly?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文