1. pom檔案中加入httpclient依賴包
2. 建立乙個呼叫httpclient的工具類
/*** 建立closeablehttpclient
/*** 建立requestconfig
*/private void
createrequestconfig()
/*** get請求不帶引數
*@param
url*
@return
*@throws
exception
*/public string doget(string url) throws exception
return null;
} /**
* get請求帶引數
*@param
url*
@param
map*
@return
*@throws
exception
*/public string doget(string url, map, object> map) throws exception
}return this.doget(uribuilder.build().tostring());
} /**
* 帶引數的post請求
* post請求不帶引數
*@param
url*
@return
*@throws
exception
*/public string dopost(string url) throws exception3. 利用unit進行單元測試
@test可以得到返回的html頁面public void
test1() catch (exception e)
4.使用開源框架jsoup進行html頁面的解析
4.1 加入jsoup依賴
4.2 jsoup解析頁面org.jsoup
jsoup
1.7.3
private voidparsehtml(string result)
for (element text : textelements)
for (element img : imgelements)
}private void
print(string str , object...msg)
private static string trim(string str, int width) else
}
Android開發實現HttpClient工具類
在android開發中我們經常會用到網路連線功能與伺服器進行資料的互動,為此android的sdk提供了apache的httpclient來方便我們使用各種http服務。你可以把httpclient想象成乙個瀏覽器,通過它的api我們可以很方便的發出get,post請求 當然它的功能遠不止這些 比如...
使用單例模式實現自己的HttpClient工具類
在android開發中我們經常會用到網路連線功能與伺服器進行資料的互動,為此android的sdk提供了apache的httpclient來方便我們使用各種http服務。你可以把httpclient想象成乙個瀏覽器,通過它的api我們可以很方便的發出get,post請求 當然它的功能遠不止這些 比如...
使用單例模式實現自己的HttpClient工具類
在android開發中我們經常會用到網路連線功能與伺服器進行資料的互動,為此android的sdk提供了apache的httpclient來方便我們使用各種http服務。你可以把httpclient想象成乙個瀏覽器,通過它的api我們可以很方便的發出get,post請求 當然它的功能遠不止這些 比如...