【问题标题】:How to perform an HTTP POST request in ASP?如何在 ASP 中执行 HTTP POST 请求?
【发布时间】:2009-09-23 02:09:53
【问题描述】:

如何在经典 asp(不是 .net)中使用 POST 数据创建 HTTP 请求?

【问题讨论】:

    标签: http post asp-classic httprequest


    【解决方案1】:

    你可以试试这样的:

    Set ServerXmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
    ServerXmlHttp.open "POST", "http://www.example.com/page.asp"
    ServerXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    ServerXmlHttp.setRequestHeader "Content-Length", Len(PostData)
    ServerXmlHttp.send PostData
    
    If ServerXmlHttp.status = 200 Then
        TextResponse = ServerXmlHttp.responseText
        XMLResponse = ServerXmlHttp.responseXML
        StreamResponse = ServerXmlHttp.responseStream
    Else
        ' Handle missing response or other errors here
    End If
    
    Set ServerXmlHttp = Nothing
    

    其中 PostData 是您要发布的数据(例如名称-值对、XML 文档或其他)。

    您需要设置正确的 MSXML2.ServerXMLHTTP 版本以匹配您已安装的版本。

    open 方法有五个参数,其中只有前两个是必需的:

    ServerXmlHttp.open Method, URL, Async, User, Password
    
    • 方法:“GET”或“POST”
    • 网址:您要发布到的网址
    • 异步:默认为 False(调用不会立即返回)- 异步调用设置为 True
    • 用户:认证所需的用户名
    • 密码:认证所需的密码

    当调用返回时,status 属性保存 HTTP 状态。值 200 表示正常 - 404 表示未找到,500 表示服务器错误等。(有关其他值,请参阅 http://en.wikipedia.org/wiki/List_of_HTTP_status_codes。)

    您可以获取文本(responseText 属性)、XML(responseXML 属性)或流(responseStream 属性)的响应。

    【讨论】:

    • "您需要设置正确版本的 MSXML2.ServerXMLHTTP 以匹配您已安装的版本。"或者只使用当前支持的所有平台上始终存在的 MSXML2.ServerXMLHTTP.3.0。
    【解决方案2】:

    您必须直接使用现有的 xmlhttp 服务器对象之一,或者您可以使用一个库,通过抽象低级别的东西使生活变得更轻松。

    检查 ajaxed implementation 获取 URL

    缺点:您需要配置库才能使其工作。不确定这是否对您的项目是必要的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-28
      • 1970-01-01
      • 2018-06-02
      • 1970-01-01
      相关资源
      最近更新 更多