用于确定 HTTP 响应是否来自预期域的脚本
我正在尝试编写一个脚本,将 HTTP“GET”发送到 URL,然后确定响应是否来自同一域。
我一直在使用 VBS 和 WinHttp.WinHttpRequest.5.1 对象。遗憾的是,这并没有让我能够了解响应的确切来源。
我尝试解析响应标头,但只有在 Web 服务器设置了包含服务器域的 cookie 时才会产生结果。例如(在下面的脚本中)“google.com”将通过,但“avg.com”将失败。
我不太喜欢我当前的脚本,如果有人知道更好的方法,我很乐意更改。
我当前的脚本:
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))
感谢一百万。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您只是希望 WinHttpRequest 对象不自动遵循重定向响应。查看 WinHttpRequestOption_EnableRedirects 选项。默认设置为 TRUE,您需要将其关闭。
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.