日期:2014-05-20  浏览次数:20758 次

关于Android用移动2G网络访问WebService的问题
写的是一个天气预报查询和一个火车票查询的一个Android小应用。
天气预报的WebService是:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
火车票的WebService是:http://www.webxml.com.cn/WebServices/TrainTimeWebService.asmx
用的是Android模拟器测试的时候都是正常的。
但是在真机上用移动2G的网络就获取数据,但是联通3G可以获取数据。


求解。。。
------解决方案--------------------
但是在真机上用移动2G的网络就获取数据,但是联通3G可以获取数据。
这话能通么。。
构建HttpGet对象来执行请求,
我现在用的是HttpPost的方法请求的,2G下测试能通。

public static String requestToProxy(HttpEntity entity, String proxy)
throws IOException {
String serverJsonStr = null;
final HttpPost post = new HttpPost(proxy);
// 添加gzip的包头
post.addHeader("Accept-Encoding", "gzip");
post.setEntity(entity);
HttpResponse httpResponse = MjUtil.getHttpClient().execute(post);

if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
entity = httpResponse.getEntity();
if (entity.getContentEncoding() != null
&& entity.getContentEncoding().getValue() != null
&& entity.getContentEncoding().getValue().contains("gzip")) {
serverJsonStr = MjUtil.guzipCompress(entity.getContent());
} else {
serverJsonStr = EntityUtils.toString(entity);
}
}
return serverJsonStr;
}