Created
December 1, 2009 17:33
-
-
Save pwlin/246467 to your computer and use it in GitHub Desktop.
Ajax with ActiveX WinHTTP 5.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://msdn.microsoft.com/en-us/library/aa384273(VS.85).aspx | |
function test_ajax(){ | |
var ajax = new ActiveXObject("WinHttp.WinHttpRequest.5.1"); | |
/* | |
// Define the constants used by the option property. | |
const WinHttpRequestOption_UserAgentString = 0; // Name of the user agent | |
const WinHttpRequestOption_URL = 1; // Current URL | |
const WinHttpRequestOption_URLCodePage = 2; // Code page | |
const WinHttpRequestOption_EscapePercentInURL = 3; // Convert percents in the URL | |
ajax.Option(WinHttpRequestOption_UserAgentString) = 'Mozilla 4.0' ; | |
*/ | |
/* | |
// HttpRequest SetCredentials flags. | |
const HTTPREQUEST_PROXYSETTING_DEFAULT = 0; | |
const HTTPREQUEST_PROXYSETTING_PRECONFIG = 0; | |
const HTTPREQUEST_PROXYSETTING_DIRECT = 1; | |
const HTTPREQUEST_PROXYSETTING_PROXY = 2; | |
// Use proxy_server for all requests outside of | |
// the microsoft.com domain. | |
ajax.SetProxy( HTTPREQUEST_PROXYSETTING_PROXY, | |
"192.168.0.2:65509", | |
"*.microsoft.com"); | |
*/ | |
ajax.Open("GET","http://www.google.com/",true); | |
//ajax.SetRequestHeader("User-Agent", "Mozilla"); | |
ajax.Send(); | |
try { | |
ajax.WaitForResponse(); | |
return ajax.ResponseText ; | |
} | |
catch(err){ | |
alert('Error:' + "\n" + err.message); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment