0
블랙 베리 플랫폼에서 http 요청을하려고합니다. 문제는 다음과 같습니다. Wi-Fi를 통해 연결하면 제대로 작동하지만 모바일 네트워크를 사용할 때 작동하지 않으며 연결모바일 네트워크를 사용할 때 http 연결이 멈 춥니 다.
을 동결하는 것은 여기에 내 코드
public static String getHttpUTFResponse(String url) {
url = addConnSuffex(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;
}
}
public static String addConnSuffex(String url) {
ServiceBook sb = ServiceBook.getSB();
ServiceRecord[] records = sb.findRecordsByCid("WPTCP");
String uid = null;
if (records == null) {
return url;
}
for (int i = 0; i < records.length; i++) {
if (records[i].isValid() && !records[i].isDisabled()) {
if (records[i].getUid() != null
&& records[i].getUid().length() != 0) {
if ((records[i].getUid().toLowerCase().indexOf("wifi") == -1)
&& (records[i].getUid().toLowerCase()
.indexOf("mms") == -1)) {
uid = records[i].getUid();
break;
}
}
}
}
if (DeviceInfo.isSimulator()) {
return url;
}
if (uid != null) {
// open a WAP 2 connection
url = url + ";deviceside=true;ConnectionUID=" + uid;
System.out.println("**************** on conn" + url);
} else {
url = url + ";deviceside=true;interface=wifi";
// Consider another transport or alternative action.
}
System.out.println("**************** on conn" + url);
return url;
}
감사합니다 더 사용하는 모든 사용자가 네트워크와 관련된 문제를 많이 해결할 수있다 네트워크 연결 TransportDetective.class에 대한 많은