我正在尝试将数据从 Textarea 发布到经典的 ASP 脚本,该脚本更新本地计算机上的 MS SQL,然后发布到另一台服务器上的 PHP 脚本。但是,执行以下操作不起作用,因为它会切断文本区域的数据。它具有用于 HTML 和其他数据的特殊字符。
所以我的问题是,如何使用 ASP Classic 通过 POST 传递这些数据?
找了一整天,希望有人能赐教,谢谢!
strUrl = "http://www.example.com/index.php"
requestData = request("request")
requestData2 = request("request2")
strData = "request=" & requestData & "&request2=" & requestData2
postHTML (strUrl, strData)
function postHTML (strUrl, strData)
Set xmlHttp = Server.Createobject("MSXML2.ServerXMLHTTP")
xmlHttp.Open "POST", strUrl, False
xmlHttp.setRequestHeader "User-Agent", "asp httprequest"
xmlHttp.setRequestHeader "content-type", "application/x-www-form-urlencoded"
xmlHttp.Send strData
postHTML = xmlHttp.responseText
xmlHttp.abort()
set xmlHttp = Nothing
end function
例如,如果 &
在 requestdata2 中,则 &
之后的任何内容都会被截断,因为它认为它正在开始一个新字符串。但我希望能够传递它。
我现在唯一能想到的解决方案:对特殊字符(例如 =
和 &
进行字符串替换,然后在 php 上用另一个字符串替换来恢复它们服务器。然而,这不是我想要完成的任务。我想要发送帖子的正确方式。
最佳答案
您需要对参数值进行 URL 编码,因此更改此行...
strData = "request=" & requestData & "&request2=" & requestData2
...到...
strData = "request=" & Server.UrlEncode(requestData) & "&request2=" & Server.UrlEncode(requestData2)
接收服务器应自动解码这些值。
关于post - 通过 HTTP 请求 POST 发送 Post 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12358945/