各位it精英们,请问一下,我开发了一个天气与报的android软件,它是通过解析WEBSERVICE来获取天气情况的,在模拟器上可以访问,但是用手机时便不可以访问,请问如何使用GPRS访问webservice来获取天气预报啊? 

解决方案 »

  1.   

    /*************************************
     * 获取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);
    }
    }
    我这边正常运行,你参考下看看。或者是你检查下有没有给权限。
      

  2.   

    把真机的移动网络设置成wap就好了