BlackBerry应用无法与服务器建立Http连接 [英] BlackBerry app unable to establish Http Connection with server
本文介绍了BlackBerry应用无法与服务器建立Http连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我用于HTTP连接的代码:
HttpConnection connection = null;
// InputStream inputstream = null;
connection =(HttpConnection)Connector.open(http://www.google.com);
// HTTP请求
connection.setRequestMethod(HttpConnection.GET);
connection.setRequestProperty(Content-Type,// text plain);
connection.setRequestProperty(Connection,close);
add(new LabelField(+ connection.getResponseMessage()));
connection.close();这个BlackBerry开发指南标题为 http://docs.blackberry.com/en/developers/deliverables/11938/CS_create_first_available_HTTP_connection_857706_11.jsprel =nofollow noreferrer>代码示例:使用第一个可用的传输方式通过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());
}
}
This is the code that I am using for an HTTP connection:
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();
解决方案 This BlackBerry Development Guide titled "Code sample: Creating a connection over HTTP by using the first available transport" worked!!
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());
}
}
这篇关于BlackBerry应用无法与服务器建立Http连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文