- 資訊首頁(yè) > 開(kāi)發(fā)技術(shù) > web開(kāi)發(fā) > ASP >
- Asp WinHttp.WinHttpRequest.5.1 對象使用詳解 偽造 HTTP
由于微軟封鎖了 XmlHttp 對象,所以無(wú)法偽造部分 HTTP 頭信息,但是 WinHttp.WinHttpRequest.5.1 對象,它居然用可以成功偽造所有 http 請求的 header 信息!
從msdn得知,WinHttp.WinHttpRequest.5.1 是 msxml 4.0 的底層對象,也就是說(shuō) XMLHTTP/ServerXMLHTTP 也是在它的基礎上封裝而來(lái),WinHttpRequest 的用法與 XmlHttp 大致相同。
WaitForResponse 在使用異步方式發(fā)送請求時(shí),可以用這個(gè)方法來(lái)控制請求的進(jìn)程,指定的等待時(shí)間,以秒為一個(gè)異步傳送方法來(lái)完成的值,SetTimeouts。
在服務(wù)端腳本中,不可以像客戶(hù)端那樣直接使用回調函數來(lái)控制異步請求,也沒(méi)有相應的函數來(lái)使用程序休眠一定的時(shí)間,因此,為了等待請求返回,我們可以使用這個(gè)方法來(lái)等待一定時(shí)間。
代碼如下:
<%
Dim WinHttp
Set WinHttp = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
'設置參數
WinHttp.SetTimeouts 60000, 60000, 60000, 3000 '設置操作超時(shí)時(shí)間
'WinHttp.SetTimeouts resolveTimeout, connectTimeout, sendTimeout, receiveTimeout
'resolveTimeout = 10000 '解析 DNS 名字的超時(shí)時(shí)間,10000 毫秒。
'connectTimeout = 10000 '建立 Winsock 連接的超時(shí)時(shí)間,10000 毫秒。
'sendTimeout = 120000 '發(fā)送數據的超時(shí)時(shí)間,120000 毫秒。
'receiveTimeout = 60000 '接收 response 的超時(shí)時(shí)間,60000 毫秒。
WinHttp.Option(4) = 13056 '忽略錯誤標志
WinHttp.Option(6) = False '為 True 時(shí),當請求頁(yè)面重定向跳轉時(shí)自動(dòng)跳轉,False 不自動(dòng)跳轉,截取服務(wù)端返回的302狀態(tài)。
WinHttp.Open "GET", "http://www.baidu.com/", False 'GET 或 POST, Url, False 同步方式;True 異步方式
'組成 HTTP 頭信息
WinHttp.SetRequestHeader "Accept", "*/*" '接受數據類(lèi)型
WinHttp.SetRequestHeader "Accept-Language", "zh-cn,zh" '用戶(hù)系統語(yǔ)言
WinHttp.SetRequestHeader "User-Agent", "Mozilla/6.0" '用戶(hù)瀏覽器信息
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) '內容長(cháng)度,Post 方式用的。
WinHttp.SetRequestHeader "Cookie", "test cookie!" '設置 Cookie
'發(fā)送數據
WinHttp.Send 'Post 方式:WinHttp.Send (參數)
WinHttp.WaitForResponse '等待返回請求,XMLHTTP中也可以使用
'輸出結果
Response.Write WinHttp.Status '當前 HTTP 狀態(tài)
'Response.Write WinHttp.ResponseText '文本數據
Response.BinaryWrite WinHttp.ResponseBody '二進(jìn)制數據流數據
%>
Option()相關(guān):
WinHttpRequestOption_UserAgentString = 0;
WinHttpRequestOption_URL = 1;
WinHttpRequestOption_URLCodePage = 2;
WinHttpRequestOption_EscapePercentInURL = 3;
WinHttpRequestOption_SslErrorIgnoreFlags = 4;
WinHttpRequestOption_SelectCertificate = 5; '13056 = 忽略錯誤標志
WinHttpRequestOption_EnableRedirects = 6; '為T(mén)rue時(shí),當請求的頁(yè)面中有跳轉時(shí),抓取跳轉頁(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響應頭。
GetResponseHeader 檢索HTTP響應頭。
Open 打開(kāi)一個(gè)HTTP連接到HTTP資源。
Send 發(fā)送一個(gè)HTTP請求到HTTP服務(wù)器。
SetAutoLogonPolicy 設置當前自動(dòng)登錄策略。
SetClientCertificate 選擇一個(gè)客戶(hù)端ssl/' target='_blank'>證書(shū)發(fā)送到一個(gè)安全的超文本傳輸協(xié)議(HTTPS)服務(wù)器。
SetCredentials 設置要使用的憑據與HTTP服務(wù)器,要么是原籍國或代理服務(wù)器。
SetProxy 設置代理服務(wù)器信息。
SetRequestHeader 添加,更改或刪除一個(gè)HTTP請求標頭。
SetTimeouts 指定以毫秒為單位,個(gè)人的時(shí)間超過(guò)了一個(gè)組件發(fā)送/接收操作。
WaitForResponse 指定的等待時(shí)間,以秒為一個(gè)異步傳送方法來(lái)完成的值,SetTimeouts。
該 WinHttpRequest 對象定義以下屬性。
屬性 訪(fǎng)問(wèn)類(lèi)型 說(shuō)明
Option 讀/寫(xiě) 設置或檢索一個(gè)WinHTTP的選項值。
ResponseBody 只讀 檢索作為無(wú)符號字節數組的響應實(shí)體機構。
ResponseStream 只讀 檢索機構作為響應實(shí)體的IStream。
ResponseText 只讀 作為文本檢索響應實(shí)體機構。
Status 只讀 從上次檢索響應的HTTP狀態(tài)代碼。
StatusText 只讀 獲取HTTP狀態(tài)的文本。
Events 活動(dòng)
The WinHttpRequest object defines the following events.
WinHttpRequest 對象定義的下列事件。
Event 事件 Description說(shuō)明
OnError Occurs when there is a run-time error in the application.
當發(fā)生一個(gè)應用程序運行時(shí)錯誤時(shí)發(fā)生。
OnResponseDataAvailable Occurs when data is available from the response.
當響應數據可用時(shí)發(fā)生。
OnResponseFinished Occurs when the response data is complete.
響應數據完成時(shí)發(fā)生。
OnResponseStart Occurs when the response data starts to be received.
開(kāi)始收到響應數據時(shí)發(fā)生。
Remarks 備注
The WinHttpRequest object uses the IErrorInfo interface to provide error data.
該 WinHttpRequest 對象使用 IErrorInfo 接口來(lái)提供錯誤數據。
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.
注意:對于 Windows XP 和 Windows 2000,請參閱運行時(shí)間要求。
Requirements 要求
最低支持的客戶(hù)端 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
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站