Plus is replaced with space when sending data with HttpWebRequest

M

Mateo

(As.Net 1.1 framework!)

Hi!



So, I have problem as described in subject.

Here is source code:



Public Sub SendFormData(ByVal sUrl As String, ByVal sFormData As String) As
String



Try



Dim sbHTMLResponse As New StringBuilder

Dim byte_data As Byte() = Encoding.UTF8.GetBytes(sFormData.ToString)

Dim NewRequest As HttpWebRequest = CType(WebRequest.Create(sUrl),
HttpWebRequest)



NewRequest.Method = "POST"

NewRequest.ContentType = "application/x-www-form-urlencoded"

NewRequest.ContentLength = byte_data.Length

NewRequest.AllowAutoRedirect = False



Dim oNewRequestStream As Stream = NewRequest.GetRequestStream()



oNewRequestStream.Write(byte_data, 0, byte_data.Length)

oNewRequestStream.Close()





Catch ex As Exception



Response.Write("Exception happend!")



End Try



End Sub





I have sent this string:



sgGCXlQlpbn+rBOotb8jiZ/xVrUXBOl2kx9LGsjrmtOoazaf85A6ryXiuB+OglO6OWJ+gUT7M4v+ilaF8kmrOP5JqxYwODcPVhI4UIbYhWeJ4JibpDxpbaf2kVLeU/0Z7iwM9XgR9ho4



Other applications (asp.net application on same server, asp.net application
on other server and php application on other server) receive this string
(please note that the '+' becomed space):



sgGCXlQlpbn rBOotb8jiZ/xVrUXBOl2kx9LGsjrmtOoazaf85A6ryXiuB OglO6OWJ gUT7M4v
ilaF8kmrOP5JqxYwODcPVhI4UIbYhWeJ4JibpDxpbaf2kVLeU/0Z7iwM9XgR9ho4





Any ideas?

Only connection I have found between '+' and space is in some old cgi
article about URL encoding where space is coded as '+'. But this is FORM
POST method... And '+' is obviously coded as space.



Thanx in advance!
 
A

Alex Meleta

Hi Mateo,

Just .. [Using HttpUtility.UrlEncode to Encode your QueryStrings]
http://timstall.dotnetdevelopersjou...lityurlencode_to_encode_your_querystrings.htm
http://dotnetjunkies.com/Article/F9E655CC-DDE0-4A62-8599-0EBB9FE2348B.dcik

Regards, Alex
[TechBlog] http://devkids.blogspot.com



M> (As.Net 1.1 framework!)
M>
M> Hi!
M>
M> So, I have problem as described in subject.
M>
M> Here is source code:
M>
M> Public Sub SendFormData(ByVal sUrl As String, ByVal sFormData As
M> String) As String
M>
M> Try
M>
M> Dim sbHTMLResponse As New StringBuilder
M>
M> Dim byte_data As Byte() = Encoding.UTF8.GetBytes(sFormData.ToString)
M>
M> Dim NewRequest As HttpWebRequest = CType(WebRequest.Create(sUrl),
M> HttpWebRequest)
M>
M> NewRequest.Method = "POST"
M>
M> NewRequest.ContentType = "application/x-www-form-urlencoded"
M>
M> NewRequest.ContentLength = byte_data.Length
M>
M> NewRequest.AllowAutoRedirect = False
M>
M> Dim oNewRequestStream As Stream = NewRequest.GetRequestStream()
M>
M> oNewRequestStream.Write(byte_data, 0, byte_data.Length)
M>
M> oNewRequestStream.Close()
M>
M> Catch ex As Exception
M>
M> Response.Write("Exception happend!")
M>
M> End Try
M>
M> End Sub
M>
M> I have sent this string:
M>
M> sgGCXlQlpbn+rBOotb8jiZ/xVrUXBOl2kx9LGsjrmtOoazaf85A6ryXiuB+OglO6OWJ+g
M> UT7M4v+ilaF8kmrOP5JqxYwODcPVhI4UIbYhWeJ4JibpDxpbaf2kVLeU/0Z7iwM9XgR9h
M> o4
M>
M> Other applications (asp.net application on same server, asp.net
M> application on other server and php application on other server)
M> receive this string (please note that the '+' becomed space):
M>
M> sgGCXlQlpbn rBOotb8jiZ/xVrUXBOl2kx9LGsjrmtOoazaf85A6ryXiuB OglO6OWJ
M> gUT7M4v
M> ilaF8kmrOP5JqxYwODcPVhI4UIbYhWeJ4JibpDxpbaf2kVLeU/0Z7iwM9XgR9ho4
M>
M> Any ideas?
M>
M> Only connection I have found between '+' and space is in some old cgi
M> article about URL encoding where space is coded as '+'. But this is
M> FORM POST method... And '+' is obviously coded as space.
M>
M> Thanx in advance!
M>
 
M

Mateo

Hi Alex!

This is article aout QueryString and I cannotuse GET method, I must use FORM
POST method to send this data. I'm sending data to credit card company and
I should send them some kind of hash wich may contain plus sign. I have
server side hash calcualtion so I send those data with HttpWebRequest object
from server. When I send those data, they receive my data with spaces except
plus signs.

I', out of ideas... why should "+" be encoded as white space.... it should
be vice versa... :(
.....
 
Top