通过GPRS(移动网络)HttpConnection
问题描述:
我试图通过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服务已注册 由于任何一个
答
我感动我的意见,这些答案:
在Blackb ERRY建立连接的URL wireless/gprs/3g/simulator
是非常具有挑战性的,请按照下面的指针
- 对于
WiFi
在设备上,请确保您已后缀";interface=wifi"
的连接网址 - 为
GPRS/3G
在设备上,确保您有后缀为";deviceside=false;connectionUID="
BIS 和为";deviceside=false"
BES 到连接URL
更具描述性的讲解对,可以发现:
- Need Clarification ---- Http Connection/GPRS
- How to configure an IT Policy on the BlackBerry Enterprise Server to allow only the Internet Browser on the BlackBerry smartphone
- Internet Connectivity (APN?)
- Tag: APN
- Different ways to make an HTTP or socket connection
编辑:链接5是有用的OP
答
试试这个.. 这将帮助您检测模拟器,WiFi和GPRS连接
getWap2Uid();
String url = "your url";
if(DeviceInfo.isSimulator() == true)
{
conn = (StreamConnection) Connector.open(url+ ";deviceside=true");
}
else
{
if (uid != null)
{
//open a WAP 2 connection
conn = (StreamConnection) Connector.open(url + ";deviceside=true;ConnectionUID=" + uid);
}
else
{
//Consider another transport or alternative action.
conn = (StreamConnection) Connector.open(url +";deviceside=true;interface=wifi");
}
}
getWap2Uid功能在这里
public static String uid ;
static String getWap2Uid() {
ServiceRecord[] records = ServiceBook.getSB().findRecordsByCid("WPTCP");
for (int i = 0; i < records.length; i++)
{
ServiceRecord serviceRecord = records[i];
String recordName = serviceRecord.toString().toUpperCase();
if (serviceRecord.isValid() && !serviceRecord.isDisabled() &&
serviceRecord.getUid() != null && serviceRecord.getUid().length() != 0 &&
recordName.indexOf("WAP2")!=-1)
{
uid = serviceRecord.getUid();
EventLogger.logEvent(EventLogID, new String("getWap2Uid, UID="+uid).getBytes());
return uid;
}
}
return null;
}
你有没有调试的代码?你有什么异常?什么是行号? – Vimal
它挂断了这一行,int len =(int)connection.getLength();之后,len返回(-1),我也没有例外 – JustMe
你是后缀'“; deviceside = false; connectionUID =”'为** BIS **和 '“; deviceside = false为** BES * *到连接网址? – Vimal