多语言展示
当前在线:302今日阅读:176今日分享:34

通过HttpClient请求webService

本文使用的是查询手机号码归属地的Web
工具/原料

eclipse

方法/步骤
1

service:http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl。查询的主要方法:http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?op=getMobileCodeInfo

2

可以看出该方法的两个传入参数的名称。

3

下面直接上代码 [java] view plaincopyprivate void getMobileCodeInfo(){           try {                   final String SERVER_URL = 'http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo'; // 定义需要获取的内容来源地址                   HttpPost request = new HttpPost(SERVER_URL);                     List params = new ArrayList();                   params.add(new BasicNameValuePair('mobileCode', '136370628'));  //(注意这里的号码必须大于6位)                   params.add(new BasicNameValuePair('userId', ''));                    request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));                    HttpResponse httpResponse = new DefaultHttpClient().execute(request);                     if (httpResponse.getStatusLine().getStatusCode() != 404)                   {                           String result = EntityUtils.toString(httpResponse.getEntity());                           System.out.println(result);                    }           } catch (Exception e) {               Log.e('eee', ''+e);           e.printStackTrace();           }   }

推荐信息