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?

Community
  • 1
  • 1
greener
  • 4,989
  • 13
  • 52
  • 93

2 Answers2

0

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.

Nathan Rice
  • 3,091
  • 1
  • 20
  • 30
  • Thanks but I'm afraid that didn't do it. I still get: `userNamepasswordfNamelNameABC123wzbtw88gJoeBloggs` It's as though it doesn't recognize the line feeds or tabs.. – greener Feb 24 '12 at 10:24
  • It seems that as soon as ASP/VB handles the POST using the Request method, the line feeds and tabs are escaped. – greener Feb 24 '12 at 11:18
  • Hi greener, I updated my answer. You can possibly use that to decode the URL string? – Nathan Rice Feb 24 '12 at 17:33
  • Wireshark is showing the "\" and "n" characters but when I request them using the ASP Request method, they are not there so I can't do replace. I can even see in the hex view the "0a"s and "09"s. – greener Feb 24 '12 at 22:02
  • You can do a For or Do loop and loop through each character, then print out each character value with Asc() to see their ASCII values. You can then do a Replace() with the Chr() value that's reported by the Asc() function to get the desired result if none of those other suggestions work. I can add an example if you aren't sure how to do this. – Nathan Rice Feb 24 '12 at 22:11
  • Sorry natemrice. Tried your suggestion but the characters are simply not coming through. There just seems to be a problem between what Wireshark is showing and the Request.Form method. – greener Feb 27 '12 at 22:49
0

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.

greener
  • 4,989
  • 13
  • 52
  • 93