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

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

问题描述

我正在使用VBScript和Microsoft.XMLHTTP对象来抓取一些Web数据.我有一个要检查的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.

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

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).

任何想法都将不胜感激.

Any ideas would be greatly appreciated.

推荐答案

首先,您应该使用的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 上的A.

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

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