如何在 ASP 中执行 HTTP POST 请求? [英] How to perform an HTTP POST request in ASP?

查看:52
本文介绍了如何在 ASP 中执行 HTTP POST 请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How would I go about creating a HTTP request with POST data in classic asp (not .net) ?

推荐答案

你可以试试这样的:

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 文档或其他任何内容).

where PostData is the data you want to post (eg name-value pairs, XML document or whatever).

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

You'll need to set the correct version of MSXML2.ServerXMLHTTP to match what you have installed.

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

The open method takes five arguments, of which only the first two are required:

ServerXmlHttp.open Method, URL, Async, User, Password

  • 方法:GET"或POST"
  • URL:您要发布到的 URL
  • Async:默认为 False(调用不会立即返回)- 对于异步调用设置为 True
  • User:认证所需的用户名
  • 密码:认证所需的密码
  • 当调用返回时,status 属性保存 HTTP 状态.值 200 表示正常 - 404 表示未找到,500 表示服务器错误等(参见 http://en.wikipedia.org/wiki/List_of_HTTP_status_codes 其他值.)

    When the call returns, the status property holds the HTTP status. A value of 200 means OK - 404 means not found, 500 means server error etc. (See http://en.wikipedia.org/wiki/List_of_HTTP_status_codes for other values.)

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

    You can get the response as text (responseText property), XML (responseXML property) or a stream (responseStream property).

    这篇关于如何在 ASP 中执行 HTTP POST 请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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