由于微軟封鎖了 XmlHttp 對(duì)象,所以無(wú)法偽造部分 HTTP 頭信息,但是 WinHttp.WinHttpRequest.5.1 對(duì)象,它居然用可以成功偽造所有 http 請(qǐng)求的 header 信息!
從msdn得知,WinHttp.WinHttpRequest.5.1 是 msxml 4.0 的底層對(duì)象,也就是說(shuō) XMLHTTP/ServerXMLHTTP 也是在它的基礎(chǔ)上封裝而來(lái),WinHttpRequest 的用法與 XmlHttp 大致相同。
WaitForResponse 在使用異步方式發(fā)送請(qǐng)求時(shí),可以用這個(gè)方法來(lái)控制請(qǐng)求的進(jìn)程,指定的等待時(shí)間,以秒為一個(gè)異步傳送方法來(lái)完成的值,SetTimeouts。
在服務(wù)端腳本中,不可以像客戶端那樣直接使用回調(diào)函數(shù)來(lái)控制異步請(qǐng)求,也沒(méi)有相應(yīng)的函數(shù)來(lái)使用程序休眠一定的時(shí)間,因此,為了等待請(qǐng)求返回,我們可以使用這個(gè)方法來(lái)等待一定時(shí)間。
復(fù)制代碼 代碼如下:
%
Dim WinHttp
Set WinHttp = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
'設(shè)置參數(shù)
WinHttp.SetTimeouts 60000, 60000, 60000, 3000 '設(shè)置操作超時(shí)時(shí)間
'WinHttp.SetTimeouts resolveTimeout, connectTimeout, sendTimeout, receiveTimeout
'resolveTimeout = 10000 '解析 DNS 名字的超時(shí)時(shí)間,10000 毫秒。
'connectTimeout = 10000 '建立 Winsock 連接的超時(shí)時(shí)間,10000 毫秒。
'sendTimeout = 120000 '發(fā)送數(shù)據(jù)的超時(shí)時(shí)間,120000 毫秒。
'receiveTimeout = 60000 '接收 response 的超時(shí)時(shí)間,60000 毫秒。
WinHttp.Option(4) = 13056 '忽略錯(cuò)誤標(biāo)志
WinHttp.Option(6) = False '為 True 時(shí),當(dāng)請(qǐng)求頁(yè)面重定向跳轉(zhuǎn)時(shí)自動(dòng)跳轉(zhuǎn),F(xiàn)alse 不自動(dòng)跳轉(zhuǎn),截取服務(wù)端返回的302狀態(tài)。
WinHttp.Open "GET", "http://www.baidu.com/", False 'GET 或 POST, Url, False 同步方式;True 異步方式
'組成 HTTP 頭信息
WinHttp.SetRequestHeader "Accept", "*/*" '接受數(shù)據(jù)類型
WinHttp.SetRequestHeader "Accept-Language", "zh-cn,zh" '用戶系統(tǒng)語(yǔ)言
WinHttp.SetRequestHeader "User-Agent", "Mozilla/6.0" '用戶瀏覽器信息
WinHttp.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded" '編碼方式
WinHttp.SetRequestHeader "Referer", "http://www.baidu.com/" '來(lái)路
WinHttp.SetRequestHeader "Connection", "Close" 'Close = 不保持連接,Keep-Alive = 保持連接(持久連接)
'WinHttp.SetRequestHeader "Accept-Encoding", "gzip, deflate" '如果發(fā)送,會(huì)返回 gzip, deflate 壓縮過(guò)的編碼
'WinHttp.SetRequestHeader "Content-Length", Len(Str) '內(nèi)容長(zhǎng)度,Post 方式用的。
WinHttp.SetRequestHeader "Cookie", "test cookie!" '設(shè)置 Cookie
'發(fā)送數(shù)據(jù)
WinHttp.Send 'Post 方式:WinHttp.Send (參數(shù))
WinHttp.WaitForResponse '等待返回請(qǐng)求,XMLHTTP中也可以使用
'輸出結(jié)果
Response.Write WinHttp.Status '當(dāng)前 HTTP 狀態(tài)
'Response.Write WinHttp.ResponseText '文本數(shù)據(jù)
Response.BinaryWrite WinHttp.ResponseBody '二進(jìn)制數(shù)據(jù)流數(shù)據(jù)
%>
Option()相關(guān):
WinHttpRequestOption_UserAgentString = 0;
WinHttpRequestOption_URL = 1;
WinHttpRequestOption_URLCodePage = 2;
WinHttpRequestOption_EscapePercentInURL = 3;
WinHttpRequestOption_SslErrorIgnoreFlags = 4;
WinHttpRequestOption_SelectCertificate = 5; '13056 = 忽略錯(cuò)誤標(biāo)志
WinHttpRequestOption_EnableRedirects = 6; '為True時(shí),當(dāng)請(qǐng)求的頁(yè)面中有跳轉(zhuǎn)時(shí),抓取跳轉(zhuǎn)頁(yè)面信息.False相反不抓取
WinHttpRequestOption_UrlEscapeDisable = 7;
WinHttpRequestOption_UrlEscapeDisableQuery = 8;
WinHttpRequestOption_SecureProtocols = 9;
WinHttpRequestOption_EnableTracing = 10;
WinHttpRequestOption_RevertImpersonationOverSsl = 11;
WinHttpRequestOption_EnableHttpsToHttpRedirects = 12;
WinHttpRequestOption_EnablePassportAuthentication = 13;
WinHttpRequestOption_MaxAutomaticRedirects = 14;
WinHttpRequestOption_MaxResponseHeaderSize = 15;
WinHttpRequestOption_MaxResponseDrainSize = 16;
WinHttpRequestOption_EnableHttp1_1 = 17;
WinHttpRequestOption_EnableCertificateRevocationCheck = 18;
方法 Description 說(shuō)明
Abort 中止一個(gè)WinHTTP的 發(fā)送方法。
GetAllResponseHeaders 檢索所有的HTTP響應(yīng)頭。
GetResponseHeader 檢索HTTP響應(yīng)頭。
Open 打開一個(gè)HTTP連接到HTTP資源。
Send 發(fā)送一個(gè)HTTP請(qǐng)求到HTTP服務(wù)器。
SetAutoLogonPolicy 設(shè)置當(dāng)前自動(dòng)登錄策略。
SetClientCertificate 選擇一個(gè)客戶端證書發(fā)送到一個(gè)安全的超文本傳輸協(xié)議(HTTPS)服務(wù)器。
SetCredentials 設(shè)置要使用的憑據(jù)與HTTP服務(wù)器,要么是原籍國(guó)或代理服務(wù)器。
SetProxy 設(shè)置代理服務(wù)器信息。
SetRequestHeader 添加,更改或刪除一個(gè)HTTP請(qǐng)求標(biāo)頭。
SetTimeouts 指定以毫秒為單位,個(gè)人的時(shí)間超過(guò)了一個(gè)組件發(fā)送/接收操作。
WaitForResponse 指定的等待時(shí)間,以秒為一個(gè)異步傳送方法來(lái)完成的值,SetTimeouts。
該 WinHttpRequest 對(duì)象定義以下屬性。
屬性 訪問(wèn)類型 說(shuō)明
Option 讀/寫 設(shè)置或檢索一個(gè)WinHTTP的選項(xiàng)值。
ResponseBody 只讀 檢索作為無(wú)符號(hào)字節(jié)數(shù)組的響應(yīng)實(shí)體機(jī)構(gòu)。
ResponseStream 只讀 檢索機(jī)構(gòu)作為響應(yīng)實(shí)體的IStream。
ResponseText 只讀 作為文本檢索響應(yīng)實(shí)體機(jī)構(gòu)。
Status 只讀 從上次檢索響應(yīng)的HTTP狀態(tài)代碼。
StatusText 只讀 獲取HTTP狀態(tài)的文本。
Events 活動(dòng)
The WinHttpRequest object defines the following events.
WinHttpRequest 對(duì)象定義的下列事件。
Event 事件 Description說(shuō)明
OnError Occurs when there is a run-time error in the application.
當(dāng)發(fā)生一個(gè)應(yīng)用程序運(yùn)行時(shí)錯(cuò)誤時(shí)發(fā)生。
OnResponseDataAvailable Occurs when data is available from the response.
當(dāng)響應(yīng)數(shù)據(jù)可用時(shí)發(fā)生。
OnResponseFinished Occurs when the response data is complete.
響應(yīng)數(shù)據(jù)完成時(shí)發(fā)生。
OnResponseStart Occurs when the response data starts to be received.
開始收到響應(yīng)數(shù)據(jù)時(shí)發(fā)生。
Remarks 備注
The WinHttpRequest object uses the IErrorInfo interface to provide error data.
該 WinHttpRequest 對(duì)象使用 IErrorInfo 接口來(lái)提供錯(cuò)誤數(shù)據(jù)。
A description and numerical error value can be obtained with the Err object in Microsoft Visual Basic Scripting Edition (VBScript),
and the Error object in Microsoft JScript.
The lower 16 bits of an error number correspond to the values found in Error Messages.
Note For Windows XP and Windows 2000, see Run-Time Requirements.
注意:對(duì)于 Windows XP 和 Windows 2000,請(qǐng)參閱運(yùn)行時(shí)間要求。
Requirements 要求
最低支持的客戶端 Windows XP, Windows 2000 Professional with SP3 Windows XP
最低支持的服務(wù)器 Windows Server 2003, Windows 2000 Server with SP3
可再發(fā)行 WinHTTP 5.0 and Internet Explorer 5.01 or later on Windows XP and Windows 2000.
WinHTTP的5.0和Internet Explorer 5.01或更高版本的Windows XP和Windows 2000。
IDL HttpRequest.idl HttpRequest.idl
Library Winhttp.lib Winhttp.lib
DLL Winhttp.dll Winhttp.dll
您可能感興趣的文章:- 用asp+xmlhttp編寫web采集程序
- asp.net HttpWebRequest自動(dòng)識(shí)別網(wǎng)頁(yè)編碼
- Asp.net XMLHTTP封裝類(GET,Post發(fā)送和接收數(shù)據(jù))
- 運(yùn)行asp.net時(shí)出現(xiàn) http錯(cuò)誤404-文件或目錄未找到
- Javascript+XMLHttpRequest+asp.net無(wú)刷新讀取數(shù)據(jù)庫(kù)數(shù)據(jù)
- asp.net利用HttpModule實(shí)現(xiàn)防sql注入
- asp.net 模擬提交有文件上傳的表單(通過(guò)http模擬上傳文件)
- asp頁(yè)面提示Response 對(duì)象 錯(cuò)誤 ASP 0156 : 80004005 HTTP 頭錯(cuò)誤
- asp中利用xmlhttp抓取網(wǎng)頁(yè)內(nèi)容的代碼
- Asp 使用 Microsoft.XMLHTTP 抓取網(wǎng)頁(yè)內(nèi)容并過(guò)濾需要的
- asp中使用MSXML2.ServerXMLHTTP實(shí)現(xiàn)異步請(qǐng)求例子
- 解決ASP中http狀態(tài)跳轉(zhuǎn)返回錯(cuò)誤頁(yè)的問(wèn)題