用于确定 HTTP 响应是否来自预期域的脚本

发布于 2024-09-06 19:09:05 字数 969 浏览 3 评论 0原文

我正在尝试编写一个脚本,将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掀纱窥君容 2024-09-13 19:09:05

听起来您只是希望 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文