开发了一个小程序,访问http get json .模拟器测试没问题。真机9780(WIFI,中国移动SIM卡)测试没问题。
。但是换了澳门的CTM手机卡后,只有手机自带的浏览器可以上网,我的程序不能访问网络,而且手机QQ,新浪都上不了。。。求解。
安装在别人的手机上9900(网络澳门CTM),程序访问不了网络。
private ConnectionFactory factory;
private ConnectionDescriptor conDescriptor;
private ReturnMessage retuMsg;
public HttpConnect() {
// TODO Auto-generated constructor stub
factory=new ConnectionFactory();
}
//get
public ReturnMessage parseGetJsonByUrl(String url){
retuMsg=new ReturnMessage();
InputStream is=null;
HttpConnection conn=null;
OutputStream os=null;
String temp="";
try {
conDescriptor=factory.getConnection(url);
System.out.println("url="+url);
if(conDescriptor!=null){
conn=(HttpConnection)conDescriptor.getConnection();
conn.setRequestMethod(HttpConnection.GET);
conn.setRequestProperty("User-Agent", "BlackBerry/5.0.0");
conn.setRequestProperty("Content-Type","application/json");
retuMsg.setHttpcode(conn.getResponseCode());
is=conn.openInputStream();
int length=(int)conn.getLength();
StringBuffer sb=new StringBuffer();
if(length>0){
byte servletData[]=new byte[length];
int i=-1;
while((i=is.read(servletData))!=-1){
sb.append(new String(servletData,0,i,"utf-8"));
}
temp=sb.toString();
System.out.println("chao"+temp);
}else{
System.out.println("Elex get length <0");
}
retuMsg.setJson(temp);
}
}catch (Exception e) {
// TODO: handle exception