你能用 Microsoft.XMLHTTP 对象检测到 301 重定向吗? [英] Can you detect a 301 redirect with Microsoft.XMLHTTP object?

查看:21
本文介绍了你能用 Microsoft.XMLHTTP 对象检测到 301 重定向吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 VBScript 和 Microsoft.XMLHTTP 对象来抓取一些网络数据.我有一个要检查的 URL 列表,但不幸的是,其中一些 301 重定向到列表中的其他 URL,因此我最终得到了冗余数据.

I'm using VBScript and the Microsoft.XMLHTTP object to scrape some web data. I have a list of URLs to check, but unfortunately some of them 301 redirect to others on the list, so I wind up with redundant data.

是否有可能使 XMLHTTP 对象在 301 重定向时失败?或者至少缓存原始响应头?或者只是让我知道发生了什么?

Is it at all possible to make the XMLHTTP object fail on 301 redirect? Or at least cache the original response header? Or otherwise just let me know what happened?

(注意:我无法控制我从中请求数据的服务器;当我获得新数据时,我可以检查它是否是多余的,但如果可能的话,我想避免这种情况).

(notes: I have no control over the server I'm requesting data from; when I get new data, I could check if it's redundant, but I'd like to avoid that if possible).

任何想法将不胜感激.

推荐答案

首先,您应该使用的 ProgId 是 MSXML2.XMLHTTP.

答案是, - MSXML2.XMLHTTP 自动跟随重定向.

The answer is, No - MSXML2.XMLHTTP automatically follows redirects.

如果您需要跟踪和选择不跟踪重定向,则可以使用 WinHttp.WinHttpRequest 对象,它与 MSXML2.XMLHTTP 一样可被脚本访问.事实上,这是 MSXML2.XMLHTTP 委托给的对象,用于 http 加载.

If you need to track and optionally not follow redirects, then you can use the WinHttp.WinHttpRequest object, which, like MSXML2.XMLHTTP is accessible to script. In fact this is the object that MSXML2.XMLHTTP delegates to, for http loading.

您需要设置 WinHttpRequestOptions 到 EnableRedirects.

You'll need to set the WinHttpRequestOptions to EnableRedirects.

请参阅此问答;有关更多信息,请访问 social.msdn.microsoft.com.

这篇关于你能用 Microsoft.XMLHTTP 对象检测到 301 重定向吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆