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

标签 asp-classic http-headers httprequest

我正在调用外部 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/

相关文章:

SQL:使用条件显示链接选项

iis - 经典的 ASP 和 COM 调试

http - Angular2 HTTP - 提供非空 HTTP 内容类型 header *Safari*

scala - 使用 Netty 和 Scala Actor 的异步 http 请求

asp-classic - 经典的asp cint

c# - ASP 到 ASP.NET 帮助函数

php - 使用 Curl PHP 获取最终重定向

iOS - 多部分/表单数据发布

c++ - 从 apache2 模块发出 HTTP 请求 (c++)

objective-c - 使用 NSURLConnection 可取消的 NSOperation