程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> httpwebrequest-the response string from baidu

httpwebrequest-the response string from baidu

編輯:編程綜合問答
the response string from baidu

** i send the request string to www.baidu.com:**

GET / HTTP/1.1
Host: www.baidu.com
User-Agent: Mozilla/5.0 (X11; Linux x86_**64; rv:31.0) Gecko/20100101 Firefox/31.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Cookie: BAIDUID=9C08E9A7478B349B70427EE7A5BBC2D5:FG=1; BAIDUPSID=9C08E9A7478B349B70427EE7A5BBC2D5; BDUSS=QxT2h3RW9qMU5WVm9MWU9tNm5hfmZZU2VPMFhXVUhhd2Z5bU5mZmxybWlCbjlVQVFBQUFBJCQAAAAAAAAAAAEAAABZ0NELbGlmYW5neHZhAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKJ5V1SieVdUNG; BD_UPN=133352
Connection: keep-alive

so i can get some apply string part 1:

HTTP/1.1 200 OK
Date: Sat, 10 Jan 2015 12:30:11 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: Keep-Alive
Cache-Control: private
Expires: Sat, 10 Jan 2015 12:30:11 GMT
Content-Encoding: gzip
Server: BWS/1.1
BDPAGETYPE: 2
BDQID: 0x8c10a2fd00002a56
BDUSERID: 198299737
Set-Cookie: BDSVRTM=203; path=/
Set-Cookie: BD_HOME=1; path=/
Set-Cookie: H_PS_PSSID=1466_10674_10873_10502_10500_11059_11067_10923_10700_10990_10618; path=/; domain=.baidu.com

and part 2:

"\355\275k\227\034\307q \372Y\374\025\315\036\021\063\
003t\367ԣ\237\323l\340\002\003\200\204\004\200\217\001\251\a\t\367\251\256Gw\0
01\325Uͪ\352y\260\331\347X\336\265%\257,K:Z\277\326\336뵏\345ױ%\371Z\273\346
\245M\371\234\373[\b>>\355_\270\031\371\250\312\314ʪ\356!A\313\364\212C\314tgF
fFfFFDFFF>\377\354\315\310N\317\027nm\226\316\203\253\317\303\357\332\331<\b\22
3\321,M\027\207\a\a\247\247\247\255S\263\025\305\323\003}0\030\034\234Q@\327r..."

from part 1,i see this "Content-Encoding: gzip",
so i try to decompress the part 2 string using zlib.h.
but the function "ret = inflate(&strm, Z_NO_FLUSH);"
return -3 : Z_DATA_ERROR means that invalid or incomplete deflate data.
if you can help me ,please.

最佳回答:


參考C/C++ 解壓縮deflate編碼

花了多半天終於調試了zlib,結果解決結果總是 Z_DATA_ERROR ,看來是輸入數據有誤也就是網站返回的數據有誤。仔細看了頭部, Transfer-Encoding: chunked,說明數據是經過分段傳輸過來,再次驗證了一下解析chunked傳輸方式無誤。為什麼老是錯誤呢。。。。。。 於是自己把文件內容用deflate壓縮再解壓,結果OK代碼正確。只是錯誤,說明輸入數據格式有誤,zlib庫不認。我用的是firefox浏覽器,在網站顯示正常,firefox是開源的,下載源碼果斷看看。在mozilla-release\netwerk\streamconv\converters\ nsHTTPCompressConv.cpp 仔細看了好一陣子果然發現了貓膩
你可以參考一下nsHTTPCompressConv.cpp

lifangxva
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved