http - BlackBerry 应用程序无法与服务器建立 Http 连接

标签 http connection blackberry-simulator blackberry-eclipse-plugin

这是我用于 HTTP 连接的代码:

HttpConnection connection = null;
// InputStream inputstream = null;
connection = (HttpConnection) Connector.open("http://www.google.com");
//HTTP Request
connection.setRequestMethod(HttpConnection.GET);
connection.setRequestProperty("Content-Type","//text plain");
connection.setRequestProperty("Connection", "close");
add(new LabelField(""+connection.getResponseMessage()));
connection.close();

最佳答案

标题为“Code sample: Creating a connection over HTTP by using the first available transport”的黑莓开发指南有效!!

ConnectionFactory connFact = new ConnectionFactory();
ConnectionDescriptor connDesc;
connDesc = connFact.getConnection("http://www.google.com");
if (connDesc != null) {
    HttpConnection httpConn;
    httpConn = (HttpConnection)connDesc.getConnection();
    try { 
        final int iResponseCode = httpConn.getResponseCode();
        UiApplication.getUiApplication().invokeLater(new Runnable() {
            public void run() {
                Dialog.alert("Response code: " + 
                    Integer.toString(iResponseCode));
            }
        });
    } catch (IOException e) {
        System.err.println("Caught IOException: " + e.getMessage());
    }
}

关于http - BlackBerry 应用程序无法与服务器建立 Http 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3530927/

相关文章:

login - Freenode 上的 Xchat - 奇怪的行为

java - 我的自定义应用程序的连接池

blackberry - 避免在单击按钮时显示菜单

blackberry - eclipse中调试黑莓应用 "source not found"问题

blackberry-10 - 使 : *** No rule to make target `Device-Debug' . 停止。

http - 防御点击劫持

web-services - 哪种是创建 REST Web 服务的正确方法?

http - 为什么 ETag 不足以使浏览器缓存失效?

ruby - 在没有 rails 的情况下将 POST 参数转换为 Ruby 中的哈希

php - 为什么我不断收到错误 500 (mySQL)?