Can you detect a 301 redirect with Microsoft.XMLHTTP object?

我与影子孤独终老i 提交于 2020-01-04 02:18:28

问题


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.

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.


回答1:


First, the ProgId you should be using is MSXML2.XMLHTTP.

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

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.

You'll need to set the WinHttpRequestOptions to EnableRedirects.

See this Q&A on social.msdn.microsoft.com for more.



来源:https://stackoverflow.com/questions/2594234/can-you-detect-a-301-redirect-with-microsoft-xmlhttp-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!