我正在调用外部 API。令人烦恼的是,它返回的数据位于 header 中(文本响应为空)。
如何访问响应的 header ?
这就是我正在尝试的:
Dim httpRequest, postResponse
Set httpRequest = Server.CreateObject("MSXML2.ServerXMLHTTP")
httpRequest.Open "POST", "http://www.api.com", False, "un", "pw"
httpRequest.SetRequestHeader "Content-Type", "application/json"
httpRequest.setRequestHeader "Content-Length", len(jsondata)
httpRequest.Send data
if httpRequest.status = 200 then
response.write httpRequest.getResponseHeader
response.write httpRequest.ResponseText
end if
Set httpRequest = nothing
但它给了我:
msxml3.dll error '80072f76'
The requested header was not found
还有一个额外的问题:我刚刚注意到“MSXML2.ServerXMLHTTP”的“XML”部分 - 我使用的是正确的协议(protocol)吗?它一直适用于直接帖子,直到现在。
最佳答案
您需要指定 response header 的名称您想要检索:
response.write httpRequest.getResponseHeader("SomeHeaderName")
响应头不只有一个。可能有很多。您拥有标准响应 header ,例如 Content-Type
,并且还可以拥有自定义 header 。
And a bonus question: I just noticed the "XML" part of "MSXML2.ServerXMLHTTP" - am I using the right protocol?
是的,绝对是,这是经典 ASP 应用程序用来发送 HTTP 请求的正确 COM 对象。
关于asp-classic - 如何访问Http请求中的响应头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17249369/