Use WinHttpRequest to forge HTTP header information, forge Referer and other information. Since Microsoft has blocked the XmlHttp object, some HTTP header information cannot be forged, but the WinHttp.WinHttpRequest.5.1 object can actually successfully forge the header information of all http requests!
We learned from msdn that WinHttp.WinHttpRequest.5.1 is the underlying object of msxml 4.0, which means that XMLHTTP/ServerXMLHTTP is also encapsulated on its basis. The usage of WinHttpRequest is roughly the same as that of XmlHttp.
WaitForResponse When sending a request in an asynchronous manner, you can use this method to control the process of the request. The specified waiting time, in seconds, is the value to be completed by an asynchronous transmission method, SetTimeouts.
In server-side scripts, you cannot directly use callback functions to control asynchronous requests like the client does, and there is no corresponding function to use the program to sleep for a certain period of time. Therefore, in order to wait for the request to return, we can use this method to wait for a certain period of time. .
Copy the code code as follows:
<%
DimWinHttp
Set WinHttp = Server.CreateObject(WinHttp.WinHttpRequest.5.1)
'Set parameters
WinHttp.SetTimeouts 60000, 60000, 60000, 3000 'Set operation timeout
'WinHttp.SetTimeouts resolveTimeout, connectTimeout, sendTimeout, receiveTimeout
'resolveTimeout = 10000 'Timeout for resolving DNS names, 10000 milliseconds.
'connectTimeout = 10000 'Timeout for establishing Winsock connection, 10000 milliseconds.
'sendTimeout = 120000 'Timeout for sending data, 120000 milliseconds.
'receiveTimeout = 60000 'Timeout for receiving response, 60000 milliseconds.
WinHttp.Option(4) = 13056 'Ignore error flag
WinHttp.Option(6) = False 'When it is True, it will automatically jump when the requested page is redirected. False will not automatically jump and intercept the 302 status returned by the server.
WinHttp.Open GET, http://www.baidu.com/, False 'GET or POST, Url, False synchronous mode; True asynchronous mode
'Compose HTTP header information
WinHttp.SetRequestHeader Accept, */* 'Accept data type
WinHttp.SetRequestHeader Accept-Language, zh-cn,zh 'User system language
WinHttp.SetRequestHeader User-Agent, Mozilla/6.0 'User browser information
WinHttp.SetRequestHeader Content-Type, application/x-www-form-urlencoded 'Encoding method
WinHttp.SetRequestHeader Referer, http://www.baidu.com/ 'Source
WinHttp.SetRequestHeader Connection, Close 'Close = do not keep the connection, Keep-Alive = keep the connection (persistent connection)
'WinHttp.SetRequestHeader Accept-Encoding, gzip, deflate 'If sent, gzip, deflate compressed encoding will be returned
'WinHttp.SetRequestHeader Content-Length, Len(Str) 'Content length, used in Post method.
WinHttp.SetRequestHeader Cookie, test cookie! 'Set Cookie
'Send data
WinHttp.Send 'Post method: WinHttp.Send (parameter)
WinHttp.WaitForResponse 'Wait for return request, can also be used in XMLHTTP
'Output results
Response.Write WinHttp.Status 'Current HTTP status
'Response.Write WinHttp.ResponseText 'Text data
Response.BinaryWrite WinHttp.ResponseBody 'Binary data stream data
%>
Option() related:
WinHttpRequestOption_UserAgentString = 0;
WinHttpRequestOption_URL = 1;
WinHttpRequestOption_URLCodePage = 2;
WinHttpRequestOption_EscapePercentInURL = 3;
WinHttpRequestOption_SslErrorIgnoreFlags = 4;
WinHttpRequestOption_SelectCertificate = 5; '13056 = Ignore error flags
WinHttpRequestOption_EnableRedirects = 6; 'When True, when there is a jump in the requested page, grab the jump page information. False will not grab it on the contrary.
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;
MethodDescription
Abort aborts a WinHTTP send method.
GetAllResponseHeaders retrieves all HTTP response headers.
GetResponseHeader retrieves HTTP response headers.
Open Opens an HTTP connection to an HTTP resource.
Send sends an HTTP request to the HTTP server.
SetAutoLogonPolicy sets the current automatic login policy.
SetClientCertificate Selects a client certificate to send to a Hypertext Transfer Protocol Secure (HTTPS) server.
SetCredentials Sets the credentials to be used with the HTTP server, either the origin or proxy server.
SetProxy sets proxy server information.
SetRequestHeader Adds, changes or removes an HTTP request header.
SetTimeouts specifies, in milliseconds, the individual elapsed time for a component send/receive operation.
WaitForResponse Specifies the wait time, in seconds, for an asynchronous transfer method to complete a value, SetTimeouts.
The WinHttpRequest object defines the following properties.
Property access type description
Option Read/write sets or retrieves a WinHTTP option value.
ResponseBody Read-only Retrieves the response entity body as an unsigned byte array.
ResponseStream read-only Retrieve the IStream as the response entity.
ResponseText Read only as the text retrieved from the response entity body.
Status read-only HTTP status code from the last time the response was retrieved.
StatusText read-only gets the text of the HTTP status.
Events
The WinHttpRequest object defines the following events.
The following events are defined by the WinHttpRequest object.
Event Event Description
OnError Occurs when there is a run-time error in the application.
Occurs when an application runtime error occurs.
OnResponseDataAvailable Occurs when data is available from the response.
Occurs when response data is available.
OnResponseFinished Occurs when the response data is complete.
Occurs when response data is complete.
OnResponseStart Occurs when the response data starts to be received.
Occurs when response data starts to be received.
Remarks
The WinHttpRequest object uses the IErrorInfo interface to provide error data.
The WinHttpRequest object uses the IErrorInfo interface to provide error data.
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.
Note: For Windows XP and Windows 2000, see Runtime Requirements.
Requirements
Minimum supported clients Windows XP, Windows 2000 Professional with SP3 Windows XP
Minimum supported server Windows Server 2003, Windows 2000 Server with SP3
Redistributable for WinHTTP 5.0 and Internet Explorer 5.01 or later on Windows XP and Windows 2000.
WinHTTP 5.0 and Internet Explorer 5.01 or higher for Windows XP and Windows 2000.
IDL HttpRequest.idl HttpRequest.idl
Library Winhttp.lib Winhttp.lib
DLL Winhttp.dll Winhttp.dll