解析具有意外 URL 编码的 POST 请求

发布于 2025-01-08 00:48:21 字数 891 浏览 3 评论 0原文

此问题遵循之前的问题

以下是重现该问题的一些代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

强辩 2025-01-15 00:48:21

尝试:

 Replace(Request.Form("accountRequest"), vbLF, vbCRLF))

或者:

 Replace(Request.Form("accountRequest"), vbLF, "<br>"))|

根据您显示它的位置,两者都应该有效。

或者可能是这样的:

Function URLDecode(sConvert)
  Dim aSplit
  Dim sOutput
  Dim I
  If IsNull(sConvert) Then
     URLDecode = ""
     Exit Function
  End If

  ' convert all pluses to spaces
  sOutput = REPLACE(sConvert, "+", " ")

  ' next convert %hexdigits to the character
  aSplit = Split(sOutput, "%")

  If IsArray(aSplit) Then
    sOutput = aSplit(0)
    For I = 0 to UBound(aSplit) - 1
      sOutput = sOutput & _
        Chr("&H" & Left(aSplit(i + 1), 2)) &_
        Right(aSplit(i + 1), Len(aSplit(i + 1)) - 2)
    Next
  End If

  URLDecode = sOutput
End Function

从这里: http://www.aspnut.com/reference/encoding.asp< /a>

如果它们作为实际的“\”和“n”字符通过线路出现,您可以使用适当的 vbCRLF 和 vbTAB 常量替换这些字符。

Try:

 Replace(Request.Form("accountRequest"), vbLF, vbCRLF))

Or:

 Replace(Request.Form("accountRequest"), vbLF, "<br>"))|

Depending on where you're displaying it, either should work.

Or possibly this:

Function URLDecode(sConvert)
  Dim aSplit
  Dim sOutput
  Dim I
  If IsNull(sConvert) Then
     URLDecode = ""
     Exit Function
  End If

  ' convert all pluses to spaces
  sOutput = REPLACE(sConvert, "+", " ")

  ' next convert %hexdigits to the character
  aSplit = Split(sOutput, "%")

  If IsArray(aSplit) Then
    sOutput = aSplit(0)
    For I = 0 to UBound(aSplit) - 1
      sOutput = sOutput & _
        Chr("&H" & Left(aSplit(i + 1), 2)) &_
        Right(aSplit(i + 1), Len(aSplit(i + 1)) - 2)
    Next
  End If

  URLDecode = sOutput
End Function

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.

这个俗人 2025-01-15 00:48:21

最后发现,如果选项卡采用“\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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文