測驗頁面:新疆時時彩走勢圖頁面
http://www.xjflcp.com/trend/analyseSSC.do?operator=codeTrend&pageCount=100
測驗環境:
win7 + CBuilder6.0 + IDHTTP控制元件
代碼:
AnsiString sURL = "http://www.xjflcp.com/trend/analyseSSC.do?operator=codeTrend&pageCount=100";
int iPageLen;
IdHTTP1->Request->UserAgent="Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13";
strHtmlText=IdHTTP1->Get(sURL.c_str());
iPageLen = strHtmlText.Length();
if (strHtmlText.Length()>0 && IdHTTP1->ResponseCode==200)
{
// 處理頁面代碼。。。。
}
測驗結果:
iPageLen為40756,只回傳部分頁面內容
第三方工具測驗結果:
采用curl以及wget
curl -o xjsscraradata.html "http://www.xjflcp.com/trend/analyseSSC.do?operator=codeTrend&pageCount=100"
wget -c "http://www.xjflcp.com/trend/analyseSSC.do?operator=codeTrend&pageCount=100"
讀取頁面結果一樣,長度任然為40756,還是頁面不全
繼續用第三方HTTP抓包軟體HttpAnalyzer分析,發現該頁面
HTTP Request Header:
========================================================================
GET /trend/analyseSSC.do?operator=codeTrend&pageCount=100 HTTP/1.1
Host: www.xjflcp.com
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.99 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4
Cookie: JSESSIONID=E13A89BEBACE1EE3549E5F888EAB8C8F; __utma=62085349.1407844871.1443609161.1444145674.1444192727.19; __utmc=62085349; __utmz=62085349.1444139783.17.2.utmcsr=baidu|utmccn=(organic)|utmcmd=organic; CNZZDATA873913=cnzz_eid%3D707946308-1443606074-%26ntime%3D1444188798
========================================================================
HTTP Response Header:
================================================
HTTP/1.1 200 OK
Server: nginx/1.0.14
Date: Wed, 07 Oct 2015 05:15:37 GMT
Content-Type: text/html;charset=gbk
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Set-Cookie: JSESSIONID=2E03576FD1F5F1F012EE454441A13D27; Path=/
Content-Encoding: gzip
=================================================
程式除錯:
如果在Request Header加入AcceptEncoding = "gzip, deflate, sdch";
IdHTTP1->Request->UserAgent="Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13";
IdHTTP1->Request->AcceptEncoding = "gzip, deflate, sdch";
strHtmlText=IdHTTP1->Get(sURL.c_str());
iPageLen = strHtmlText.Length();
if (strHtmlText.Length()>0 && IdHTTP1->ResponseCode==200)
{
// 處理頁面代碼。。。。
}
發現該回傳內容亂碼,可能是頁面壓縮,在Indy一側沒有解碼的原因,決定放棄次方法,繼續換方法除錯
在Response Header發現該頁面有Transfer-Encoding: chunked
于是覺得采用HTTP 1.0以屏蔽chunked模式
IdHTTP1->ProtocolVersion = pv1_0;
IdHTTP1->Request->UserAgent="Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13";
strHtmlText=IdHTTP1->Get(sURL.c_str());
iPageLen = strHtmlText.Length();
if (strHtmlText.Length()>0 && IdHTTP1->ResponseCode==200)
{
// 處理頁面代碼。。。。
}
徹底暈倒,結果還是一樣,求救!!!
uj5u.com熱心網友回復:
幫幫我啊 高手們,謝謝轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/91547.html
標籤:網絡及通訊開發
