導航:首頁 > 編程語言 > httpclient源代碼下載

httpclient源代碼下載

發布時間:2021-04-05 12:09:16

㈠ eclispe怎樣查看httpclient源碼

在android 6.0(API 23)中,Google已經移除了移除了Apache HttpClient相關的類
推薦使用HttpUrlConnection,如果要繼續使用需要Apache HttpClient,需要在eclipse下libs里添加org.apache.http.legacy.jar,android studio里在相應的mole下的build.gradle中加入:
android {
useLibrary 'org.apache.http.legacy'
}
上面的jar包在:**\android-sdk-windows\platforms\android-23\optional下(需要下載android 6.0的SDK)
同時也移除了SSL 和Notification的setLatestEventInfo方法

㈡ 請問有沒有HttpClient源碼

到官網下載。

㈢ 有誰知道Httpclient源碼去哪裡下載

在android寫HttpClient時,想看看源碼,結果發現點進去沒有源碼,不知道怎麼去找...SDK的source中沒有

㈣ 為什麼.net看不到httpclient的源代碼

默認的,HttpClient會使用默認的HttpClientHandler,默認的HttpClientHandler的UseCookies是true,也就是說,默認情況下HttpClient就有間接的CookieContainer可以使用。但UseCookies為true了,請求頭的Cookie就不會提交,請求頭的Cookie就不會提交,請求頭的Cookie就不會提交。所以注意了,如果把Cookie提交給伺服器的話,當UseCookies為true時,只有把cookie值一一寫入CookieContainer,提交的cookie才生效;否則只有寫入請求頭,提交的cookie才生效。

㈤ 使用java開源工具httpclient怎麼使用

使用java開源工具httpClient及jsoup抓取解析網頁數據
來源:iteye,原文
今天做項目的時候遇到這樣一個需求,需要在網頁上展示今日黃歷信息,數據格式如下
公歷時間:2016年04月11日星期一
農歷時間:猴年三月初五
天乾地支:丙申年壬辰月癸亥日
宜:求子祈福開光祭祀安床
忌:玉堂(黃道)危日,忌出行
主要包括公歷/農歷日期,以及忌宜信息的等。但是手裡並沒有現成的數據可供使用,怎麼辦呢?革命前輩曾經說過,沒有槍,沒有炮,敵(wang)人(luo)給我們造!網路上有很多現成的在線萬年歷應用可供使用,雖然沒有現成介面,但是我們可以伸出手來,自己去拿。也就是所謂的數據抓取。
這里介紹兩個使用的工具,httpClient以及jsoup,簡介如下:
HttpClient是ApacheJakartaCommon下的子項目,用來提供高效的、最新的、功能豐富的支持HTTP協議的客戶端編程工具包,並且它支持HTTP協議最新的版本和建議。HttpClient已經應用在很多的項目中,比如ApacheJakarta上很著名的另外兩個開源項目Cactus和HTMLUnit都使用了HttpClient。
httpClient使用方法如下:
1.創建HttpClient對象。
2.創建請求方法的實例,並指定請求URL。
3.調用HttpClient對象的execute(HttpUriRequestrequest)發送請求,該方法返回一個HttpResponse。
4.調用HttpResponse相關方法獲取相應內容。
5.釋放連接。
jsoup是一款Java的HTML解析器,可直接解析某個URL地址、HTML文本內容。它提供了一套非常省力的API,可通過DOM,CSS以及類似於jQuery的操作方法來取出和操作數據。
需要更多信息可以參見官網下載地址
httpClient:http://hc.apache.org/httpcomponents-client-5.0.x/index.html
jsoup:http://jsoup.org/
接下來我們直接上代碼,這里我們抓取2345在線萬年歷的數據http://tools.2345.com/rili.htm
首先我們定義一個實體類Almanac來存儲黃歷數據
Almanac.java1packagecom.likx.picker.util.bean;2
3/**4
*萬年歷工具實體類5
*
6
*@author溯源blog7
*2016年4月11日8
*/9publicclassAlmanac{10
privateStringsolar;
/*陽歷e.g.2016年4月11日星期一*/11
privateStringlunar;
/*陰歷e.g.猴年三月初五*/12
privateStringchineseAra;
/*天乾地支紀年法e.g.丙申年壬辰月癸亥日*/13
privateStringshould;
/*宜e.g.求子祈福開光祭祀安床*/14
privateStringavoid;
/*忌e.g.玉堂(黃道)危日,忌出行*/1516
publicStringgetSolar(){17
returnsolar;18
}1920
publicvoidsetSolar(Stringdate){21
this.solar=date;22
}2324
publicStringgetLunar(){25
returnlunar;26
}2728
publicvoidsetLunar(Stringlunar){29
this.lunar=lunar;30
}3132
publicStringgetChineseAra(){33
returnchineseAra;34
}3536
publicvoidsetChineseAra(StringchineseAra){37
this.chineseAra=chineseAra;38
}3940
publicStringgetAvoid(){41
returnavoid;42
}4344
publicvoidsetAvoid(Stringavoid){45
this.avoid=avoid;46
}4748
publicStringgetShould(){49
returnshould;50
}5152
publicvoidsetShould(Stringshould){53
this.should=should;54
}5556
publicAlmanac(Stringsolar,Stringlunar,StringchineseAra,Stringshould,57
Stringavoid){58
this.solar=solar;59
this.lunar=lunar;60
this.chineseAra=chineseAra;61
this.should=should;62
this.avoid=avoid;63
}64}
然後是抓取解析的主程序,寫程序之前需要在官網下載需要的jar包
AlmanacUtil.javapackagecom.likx.picker.util;importjava.io.IOException;importjava.text.SimpleDateFormat;importjava.util.Calendar;importjava.util.Date;importorg.apache.http.HttpEntity;importorg.apache.http.ParseException;importorg.apache.http.client.ClientProtocolException;importorg.apache.http.client.methods.CloseableHttpResponse;importorg.apache.http.client.methods.HttpGet;importorg.apache.http.impl.client.CloseableHttpClient;importorg.apache.http.impl.client.HttpClients;importorg.apache.http.util.EntityUtils;importorg.jsoup.Jsoup;importorg.jsoup.nodes.Document;importorg.jsoup.nodes.Element;importorg.jsoup.select.Elements;/***<STRONG>類描述</STRONG>:
2345萬年歷信息爬取工具<p>*
*@version1.0<p>*@author溯源blog*
*<STRONG>創建時間</STRONG>:2016年4月11日下午14:15:44<p>*<STRONG>修改歷史</STRONG>:<p>*<pre>*修改人
修改時間
修改內容*---------------
-------------------
-----------------------------------*</pre>*/publicclassAlmanacUtil{
/**
*單例工具類
*/
privateAlmanacUtil(){
}
/**
*獲取萬年歷信息
*@return
*/
publicstaticAlmanacgetAlmanac(){
Stringurl="http://tools.2345.com/rili.htm";
Stringhtml=pickData(url);
Almanacalmanac=analyzeHTMLByString(html);
returnalmanac;
}
/*
*爬取網頁信息
*/
privatestaticStringpickData(Stringurl){
CloseableHttpClienthttpclient=HttpClients.createDefault();
try{
HttpGethttpget=newHttpGet(url);
CloseableHttpResponseresponse=httpclient.execute(httpget);
try{
//獲取響應實體
HttpEntityentity=response.getEntity();
//列印響應狀態
if(entity!=null){
returnEntityUtils.toString(entity);
}
}finally{
response.close();
}
}catch(ClientProtocolExceptione){
e.printStackTrace();
}catch(ParseExceptione){
e.printStackTrace();
}catch(IOExceptione){
e.printStackTrace();
}finally{
//關閉連接,釋放資源
try{
httpclient.close();
}catch(IOExceptione){
e.printStackTrace();
}
}
returnnull;
}
/*
*使用jsoup解析網頁信息
*/
(Stringhtml){
StringsolarDate,lunarDate,chineseAra,should,avoid="";
Documentdocument=Jsoup.parse(html);
//公歷時間
solarDate=getSolarDate();
//農歷時間
ElementeLunarDate=document.getElementById("info_nong");
lunarDate=eLunarDate.child(0).html().substring(1,3)+eLunarDate.html().substring(11);
//天乾地支紀年法
ElementeChineseAra=document.getElementById("info_chang");
chineseAra=eChineseAra.text().toString();
//宜
should=getSuggestion(document,"yi");
//忌
avoid=getSuggestion(document,"ji");
Almanacalmanac=newAlmanac(solarDate,lunarDate,chineseAra,should,avoid);
returnalmanac;
}
/*
*獲取忌/宜
*/
(Documentdoc,Stringid){
Elementelement=doc.getElementById(id);
Elementselements=element.getElementsByTag("a");
StringBuffersb=newStringBuffer();
for(Elemente:elements){
sb.append(e.text()+"");
}
returnsb.toString();
}
/*
*獲取公歷時間,用yyyy年MM月dd日EEEE格式表示。
*@returnyyyy年MM月dd日EEEE
*/
(){
Calendarcalendar=Calendar.getInstance();
DatesolarDate=calendar.getTime();
SimpleDateFormatformatter=newSimpleDateFormat("yyyy年MM月dd日EEEE");
returnformatter.format(solarDate);
}}
為了簡單明了我把抓取解析抽象成了幾個獨立的方法,
其中pickData()方法使用httpClient來抓取數據到一個字元串中(就是在網頁上點擊查看源代碼看到的HTML源碼),analyzeHTMLByString()方法來解析抓取到的字元串,getSuggestion方法把抓取方法類似的宜忌數據抽象到了一起,另外因為公歷時間可以很容易的自己生成就沒有在網頁上爬取。
然後下面是一個測試類簡單測試下效果:AlmanacUtilTest.javapackagecom.likx.picker.util.test;publicclassAlmanacUtilTest{
publicstaticvoidmain(Stringargs[]){
Almanacalmanac=AlmanacUtil.getAlmanac();
System.out.println("公歷時間:"+almanac.getSolar());
System.out.println("農歷時間:"+almanac.getLunar());
System.out.println("天乾地支:"+almanac.getChineseAra());
System.out.println("宜:"+almanac.getShould());
System.out.println("忌:"+almanac.getAvoid());
}}
運行結果如下:
集成到實際項目中效果是這樣的:
另外最近博客一直沒怎麼更新,因為最近考慮到技術氛圍的原因,離開了對日外包行業,前往一家互聯網公司就職。說一下最近的感受,那就是一個程序員最核心的競爭力不是學會了多少框架,掌握多少種工具(當然這些對於程序員也不可或缺),而是扎實的基礎以及快速學習的能力,比如今天這個項目,從對httpClient,jsoup工具一無所知到編寫出Demo代碼總計大概1個多小時,在之前對於我來說是不可想像的,在技術氛圍濃厚的地方快速get技能的感覺,非常好。
當然本例只是一個非常淺顯的小例子,網頁上內容也很容易抓取,httpClient及jsoup工具更多強大的地方沒有體現到,比如httpClient不僅可以發送get請求,而且可以發送post請求,提交表單,傳送文件,還比如jsoup最強大的地方在於它支持仿jquery的選擇器。本例僅僅使用了最簡單的document.getElementById()匹配元素,實際上jsoup的選擇器異常強大,可以說它就是java版的jquery,比如這樣:Elementslinks=doc.select("a[href]");//awithhrefElementspngs=doc.select("img[src$=.png]");
//imgwithsrcending.pngElementmasthead=doc.select("div.masthead").first();
//divwithclass=mastheadElementsresultLinks=doc.select("h3.r>a");//directaafterh3

㈥ httpclient中怎麼使用post方法獲取html的源碼

public void clientPost()
{
String httpUrl="http://10.0.2.2:8080/JDemo/android/httpget2.jsp";
// HttpPost連接對象
HttpPost httpRequest=new HttpPost(httpUrl);
//使用NameValuePair來保存要傳遞的Post參數
List<NameValuePair> params=new ArrayList<NameValuePair>();
//添加要傳遞的參數
params.add(new BasicNameValuePair("par","HTTP_Client_android_Post"));
try {
//設置字元集
HttpEntity httpentity=new UrlEncodedFormEntity(params,"gb2312");
//請求httpRequest
httpRequest.setEntity(httpentity);
//取得HttpClient對象
HttpClient httpclient=new DefaultHttpClient();
//請求HttpCLient,取得HttpResponse
HttpResponse httpResponse=httpclient.execute(httpRequest);
//請求成功
if(httpResponse.getStatusLine().getStatusCode()==HttpStatus.SC_OK)
{
//取得返回的字元串
String strResult=EntityUtils.toString(httpResponse.getEntity());
text1.setText(strResult.trim());
}else
{
text1.setText("請求錯誤!");
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch(Exception e)
{
text1.setText(e.getMessage().toString());
}
}
純手打,望採納!

㈦ 請問有org.apache.commons.httpclient.HttpClient.*的jar是哪個該去哪兒下載

你的下載tomcat或者resin,導入這兩的程序里的包。

㈧ httpClient怎麼獲取網頁中js執行完後的網頁源碼

我做過爬蟲,對這個比較了解,如果網頁源碼中有些內容是js渲染過來的,那專你通過HttpClient直接取肯定取不到,但是屬這些數據一般都是通過非同步請求傳過來的(一般都是通過ajax的get或者post方式)。那麼你可以通過火狐瀏覽器的firebug或者chrome的審查元素,在網路選項中找到這個請求地址,再用HttpClient請求一次就可以拿到你想要的數據,但這些數據可能不是網頁源碼,一般都是json字元串。

閱讀全文

與httpclient源代碼下載相關的資料

熱點內容
編程計算體重指數怎麼做 瀏覽:965
komodoeditjava 瀏覽:183
程序調用火狐瀏覽器 瀏覽:270
chkdsk工具掃描要多久 瀏覽:950
wordpress查看日誌 瀏覽:640
美容儀器批發廠家微信 瀏覽:111
華為方舟編程怎麼用 瀏覽:611
如何在app上開通中行手機銀行 瀏覽:145
微信中收藏的文件哪裡找 瀏覽:794
scratch編程怎麼給人物設置血量 瀏覽:109
如何將數據包導入底包 瀏覽:260
三星手機應用程序閃退 瀏覽:299
華為如何設定用面容解鎖app 瀏覽:978
javaserveru上傳圖片 瀏覽:888
excel數據類型如何統一 瀏覽:451
downloads找不到文件 瀏覽:635
如何製作娛樂平台網站 瀏覽:566
視頻文件微信傳後怎麼從抖音打開 瀏覽:35
別踩白塊兒2安卓版 瀏覽:810
美國黑人工具怎麼樣 瀏覽:342

友情鏈接