gpt4 book ai didi

asp-classic - 如何访问 Http 请求中的响应 header

转载 作者:行者123 更新时间:2023-12-04 04:52:24 27 4
gpt4 key购买 nike

我正在调用外部 API。令人讨厌的是,它返回的数据位于标题中(文本响应为空)。

如何访问响应的 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 。可能有很多。您有标准的响应 header ,例如 Content-Type你也可以有自定义标题。

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 请求中的响应 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17249369/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com