如何防止 ServerXMLHTTP 自动跟随重定向(HTTP 303 请参阅其他响应)? [英] How do I prevent ServerXMLHTTP from automatically following redirects (HTTP 303 See Other responses)?

查看:23
本文介绍了如何防止 ServerXMLHTTP 自动跟随重定向(HTTP 303 请参阅其他响应)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ServerXMLHTTP 来执行 HTTP POST.返回的响应是重定向(特别是 303 See Other).ServerXMLHTTP 会自动跟随此重定向,但这会导致身份验证失败,因为它不会传播原始请求的 Authorization 标头.

I am using ServerXMLHTTP to perform an HTTP POST. The response returned is a redirect (specifically 303 See Other). ServerXMLHTTP is automatically following this redirect but this is causing an authentication failure as is not propagating the Authorization header of the original request.

有没有办法阻止自动重定向(或者确保重新发送授权标头)?

Is there a way I can prevent the automatic redirection (or alternatively ensure that the Authorization header is resent)?

推荐答案

ServerXMLHTTP 不支持拦截重定向(请参阅 Microsoft 知识库文章 308607).然而,WinHTTP 可以代替它使用,并且这确实包含一个可配置的启用重定向"选项.

ServerXMLHTTP does not support interception of redirects (see Microsoft Knowledge Base Article 308607). However WinHTTP can be used in its place and this does contain a configurable 'enable redirects' option.

如何在 VBA 中禁用 WinHTTP 重定向:

How to disable WinHTTP redirects in VBA:

webClient.Option(6) = False

上下文:

Set webClient = CreateObject("WinHttp.WinHttpRequest.5.1")
webClient.Option(6) = False 
webClient.Open "POST", "http://example.com", False
webClient.send ("")

这篇关于如何防止 ServerXMLHTTP 自动跟随重定向(HTTP 303 请参阅其他响应)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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