Skip to content

Instantly share code, notes, and snippets.

@pwlin
Created December 1, 2009 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwlin/246467 to your computer and use it in GitHub Desktop.
Save pwlin/246467 to your computer and use it in GitHub Desktop.
Ajax with ActiveX WinHTTP 5.1
// 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