I am trying to write a script that will send an HTTP "GET" to a URL then determine if the response came from the same domain or not.
I have been playing around with VBS and the WinHttp.WinHttpRequest.5.1 object. Sadly this does not give me any access to where exactly the response came from.
I tried parsing through the response headers but that only yields results if the web-server sets a cookie with the server's domain in it. For example (in my script below) "google.com" will pass but "avg.com" will fail.
I am not very attached to my current script and gladly will change if anyone knows a better way.
My current script:
Dim objWinHttp Dim strContent, strURL Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1") objWinHttp.SetTimeouts 29000, 29000, 29000, 29000 objWinHttp.Option(0) = "Website_monitor_light/1.0" objWinHttp.Option(6) = True If (InStr(WScript.Arguments.Item(0), "www.") = 1) Then URL = "http://" & WScript.Arguments.Item(0) Else URL = "http://www." & WScript.Arguments.Item(0) End If objWinHttp.Open "GET", URL On Error Resume Next objWinHttp.Send() If (objWinHttp.Status = 200) Then strContent = objWinHttp.GetAllResponseHeaders End If Wscript.Quit InStr(strContent, "domain=." & Mid(URL,12))
Thanks a million.
Sounds like you simply want the WinHttpRequest object to NOT follow redirect responses automatically. Check out the WinHttpRequestOption_EnableRedirects option. This is set to TRUE by default, you need to turn it off.