我试图通过GPRS(移动网络)在真实设备上的URL的HttpConnection,但它不返回数据,但我相同的代码通过wireliess运行良好,代码也很好地工作模拟器 我的代码是通过GPRS(移动网络)HttpConnection
public static String getHttpUTFResponse(String url) {
HttpConnection connection = null;
byte responseData[] = null;
try {
connection = (HttpConnection) new ConnectionFactory()
.getConnection(url).getConnection();
int len = (int) connection.getLength();
System.out.println(len);
if (len != -1) {
responseData = new byte[len];
DataInputStream dis;
dis = new DataInputStream(connection.openInputStream());
dis.readFully(responseData);
dis.close();
}
} catch (IOException e) {
System.out.println("Connection Error");
} finally {
if (connection != null) {
try {
connection.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
connection = null;
}
}
if (responseData != null) {
try {
return new String(responseData,"UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return null;
}
} else {
return null;
}
}
注:设备浏览器运作良好,BB服务已注册 由于任何一个
你有没有调试的代码?你有什么异常?什么是行号? – Vimal
它挂断了这一行,int len =(int)connection.getLength();之后,len返回(-1),我也没有例外 – JustMe
你是后缀'“; deviceside = false; connectionUID =”'为** BIS **和 '“; deviceside = false为** BES * *到连接网址? – Vimal