BlackBerryアプリサーバーとのHTTP接続を確立できません
-
30-09-2019 - |
質問
これは、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();
解決
このブラックベリー開発ガイド「タイトル」コードサンプル:最初の利用可能なトランスポートを使用してHTTPを介して接続を作成する「働いた!!
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());
}
}
所属していません StackOverflow