1

HTTP連接這是我使用的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(); 

回答

1

本BlackBerry開發指南標題爲「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()); 
    } 
} 
相關問題