android开发天气预报无法通过GPRS访问webservice 各位it精英们,请问一下,我开发了一个天气与报的android软件,它是通过解析WEBSERVICE来获取天气情况的,在模拟器上可以访问,但是用手机时便不可以访问,请问如何使用GPRS访问webservice来获取天气预报啊? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /************************************* * 获取web services内容 * * @param url * @param params * @return *************************************/ public static String GetResponse(String method, List<BasicNameValuePair> params) { try { String url = WSUrl; SoapObject request = new SoapObject(namespace, method); for (int i = 0, len = params.size(); i < len; i++) { request.addProperty(params.get(i).getName(), params.get(i) .getValue()); } SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); // 设置10秒超时 int timeout = 10000; // set timeout 15s MyAndroidHttpTransport transport = new MyAndroidHttpTransport(url, timeout); // AndroidHttpTransport androidHttpTransport = new // AndroidHttpTransport( // url); // androidHttpTransport.call(namespace + method, envelope); transport.call(namespace + method, envelope); SoapPrimitive result = (SoapPrimitive) envelope.getResponse(); return result.toString(); } catch (Exception e) { return "Error:calling the web services error"; } }public class MyAndroidHttpTransport extends HttpTransportSE { private int timeout = 30000; // 默认超时时间为30s public MyAndroidHttpTransport(String url) { super(url); } public MyAndroidHttpTransport(String url, int timeout) { super(url); this.timeout = timeout; } // 设置调用超时方法,默认 protected ServiceConnection getServiceConnection(String url) throws IOException { ServiceConnectionSE serviceConnection = new ServiceConnectionSE(url); serviceConnection.setConnectionTimeOut(timeout); return new ServiceConnectionSE(url); }}我这边正常运行,你参考下看看。或者是你检查下有没有给权限。 把真机的移动网络设置成wap就好了 android http连接问题 为什么我的bitmap不能保存到sd卡 EditText获得光标的方法 大侠们...快出来帮帮小弟!怎么停止android访问的页面~~~~~~~~~~~~.~~~~~~~` android 网络编程 android软件搬家 为何mkdir总是失败? 怎样实现软键盘和触摸屏的事件记录 如何让定时器不失效 android开发加载网络图片文件 Surfaceview lockCanvas 锁特定rect的问题 列表问题,不显示
* 获取web services内容
*
* @param url
* @param params
* @return
*************************************/
public static String GetResponse(String method,
List<BasicNameValuePair> params) { try {
String url = WSUrl;
SoapObject request = new SoapObject(namespace, method);
for (int i = 0, len = params.size(); i < len; i++) {
request.addProperty(params.get(i).getName(), params.get(i)
.getValue());
}
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
// 设置10秒超时
int timeout = 10000; // set timeout 15s
MyAndroidHttpTransport transport = new MyAndroidHttpTransport(url,
timeout);
// AndroidHttpTransport androidHttpTransport = new
// AndroidHttpTransport(
// url);
// androidHttpTransport.call(namespace + method, envelope); transport.call(namespace + method, envelope); SoapPrimitive result = (SoapPrimitive) envelope.getResponse();
return result.toString();
} catch (Exception e) {
return "Error:calling the web services error";
}
}
public class MyAndroidHttpTransport extends HttpTransportSE { private int timeout = 30000; // 默认超时时间为30s public MyAndroidHttpTransport(String url) {
super(url);
} public MyAndroidHttpTransport(String url, int timeout) {
super(url);
this.timeout = timeout;
} // 设置调用超时方法,默认
protected ServiceConnection getServiceConnection(String url)
throws IOException {
ServiceConnectionSE serviceConnection = new ServiceConnectionSE(url);
serviceConnection.setConnectionTimeOut(timeout);
return new ServiceConnectionSE(url);
}
}
我这边正常运行,你参考下看看。或者是你检查下有没有给权限。