代码之家  ›  专栏  ›  技术社区  ›  Ashish Agarwal

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

  •  1
  • Ashish Agarwal  · 技术社区  · 16 年前

    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();
    
    1 回复  |  直到 15 年前
        1
  •  1
  •   Michael Donohue Reno    15 年前

    这本黑莓开发指南的标题是 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());
        }
    }
    
    推荐文章