解析具有意外 URL 编码的 POST 请求
此问题遵循之前的问题。
以下是重现该问题的一些代码:
POST:
str = "accountRequest=<NewUser>" & vbLf & _
"Hello" & vbTab & "World" & vbLf & _
"</NewUser>"
Set objHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
objHTTP.open "POST", "service.asp", False
objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objHTTP.send str
response.Write(objHTTP.responseText)
Set objHTTP = Nothing
service.asp:
function w (str)
response.Write(str & "<br>")
end function
str = request.Form("accountRequest")
w(str)
w("Tabs: "& InStr(str,vbTab))
w("Lines: "& InStr(str,vbLf))
输出:
HelloWorld
Tabs: 0
Lines: 0
任何人都可以帮忙吗?
This question follows an earlier one.
Here is some code that reproduces the problem:
POST:
str = "accountRequest=<NewUser>" & vbLf & _
"Hello" & vbTab & "World" & vbLf & _
"</NewUser>"
Set objHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
objHTTP.open "POST", "service.asp", False
objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objHTTP.send str
response.Write(objHTTP.responseText)
Set objHTTP = Nothing
service.asp:
function w (str)
response.Write(str & "<br>")
end function
str = request.Form("accountRequest")
w(str)
w("Tabs: "& InStr(str,vbTab))
w("Lines: "& InStr(str,vbLf))
output:
HelloWorld
Tabs: 0
Lines: 0
Can anyone please help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试:
或者:
根据您显示它的位置,两者都应该有效。
或者可能是这样的:
从这里: http://www.aspnut.com/reference/encoding.asp< /a>
如果它们作为实际的“\”和“n”字符通过线路出现,您可以使用适当的 vbCRLF 和 vbTAB 常量替换这些字符。
Try:
Or:
Depending on where you're displaying it, either should work.
Or possibly this:
From here: http://www.aspnut.com/reference/encoding.asp
If they are coming across the wire as the actual "\" and "n" characters, you can do a replace on those characters with the appropriate vbCRLF and vbTAB constants.
最后发现,如果选项卡采用“\t”格式(与 URL 编码相反),则 ASP
Request.Form
方法不会保留选项卡。然而,PHP 的$_POST
却可以。Finally figured out that ASP
Request.Form
method doesn't preserve tabs if they're in the "\t" format (as opposed to URL encoded). However, PHP's$_POST
does.