系統(tǒng)之家 - 系統(tǒng)光盤下載網(wǎng)站!

當(dāng)前位置:系統(tǒng)之家 > 系統(tǒng)教程 > 通過HttpClient請(qǐng)求Web Service的操作

通過HttpClient請(qǐng)求Web Service的操作方法

時(shí)間:2017-01-23 17:01:28 作者:chunhua 來源:系統(tǒng)之家 1. 掃描二維碼隨時(shí)看資訊 2. 請(qǐng)使用手機(jī)瀏覽器訪問: https://m.xitongzhijia.net/xtjc/20170123/91366.html 手機(jī)查看 評(píng)論

  Web Service是一個(gè)基于可編程的Web應(yīng)用程序,由于服務(wù)端是用Web Service開發(fā)的,如果android要調(diào)用Web Service服務(wù)來獲取數(shù)據(jù),就需要通過HttpClient發(fā)送post請(qǐng)求來獲取,操作方法如下。

  方法/步驟:

  注:本文使用的是查詢手機(jī)號(hào)碼歸屬地的Web。

  1、service:https://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl。

  查詢的主要方法:https://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?op=getMobileCodeInfo

通過HttpClient請(qǐng)求Web Service的操作方法

  2、可以看出該方法的兩個(gè)傳入?yún)?shù)的名稱;

通過HttpClient請(qǐng)求Web Service的操作方法

  3、下面直接上代碼。

  1. 01[java] view plaincopy
  2. 02private void getMobileCodeInfo(){
  3. 03try {
  4. 04final String SERVER_URL = "https://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo"; // 定義需要獲取的內(nèi)容來源地址
  5. 05HttpPost request = new HttpPost(SERVER_URL);
  6. 06List<BasicNameValuePair> params = new ArrayList();
  7. 07params.add(new BasicNameValuePair("mobileCode", "136370628")); //(注意這里的號(hào)碼必須大于6位)
  8. 08params.add(new BasicNameValuePair("userId", ""));
  9. 09request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
  10. 10HttpResponse httpResponse = new DefaultHttpClient().execute(request);
  11. 11if (httpResponse.getStatusLine().getStatusCode() != 404)
  12. 12{
  13. 13String result = EntityUtils.toString(httpResponse.getEntity());
  14. 14System.out.println(result);
  15. 15}
  16. 16} catch (Exception e) {
  17. 17Log.e("eee", ""+e);
  18. 18e.printStackTrace();
  19. 19}
  20. 20}
復(fù)制代碼
[java] view plaincopy private void getMobileCodeInfo(){ try { final String SERVER_URL = "https://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo"; // 定義需要獲取的內(nèi)容來源地址 HttpPost request = new HttpPost(SERVER_URL); List<BasicNameValuePair> params = new ArrayList(); params.add(new BasicNameValuePair("mobileCode", "136370628")); //(注意這里的號(hào)碼必須大于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(); } }

通過HttpClient請(qǐng)求Web Service的操作方法

  通過HttpClient請(qǐng)求Web Service的操作方法就給大家分享到這邊了,不會(huì)操作的朋友,可以參考教程操作哦!

標(biāo)簽 Web Service

發(fā)表評(píng)論

0

沒有更多評(píng)論了

評(píng)論就這些咯,讓大家也知道你的獨(dú)特見解

立即評(píng)論

以上留言僅代表用戶個(gè)人觀點(diǎn),不代表系統(tǒng)之家立場(chǎng)

其他版本軟件

人氣教程排行

相關(guān)系統(tǒng)推薦

官方交流群 軟件收錄