Click here to Skip to main content
15,886,815 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I use vb.NET. My question is pertaining to ASP.NET.
I'm POSTing using the WebClient in .NET to PayPal servers. There is an issue where some characters are being encoded. Particularly the @ symbol within an email address. The PayPal staff are telling me that the eMail is being POSTed as "name%40domain.com". The @ has been swapped out for %40

I have changed the encoding of the WebClient in numerous ways but nothing has helped. The tech at PayPal says that the server might have something to do with this automatic encoding. I contacted my domain admin and they had no clue.

Is there anyways I can stop the encoding of this POST and send the @ symbol within the email without it being encoded?

A snippet of my code where I'm changing the encoding to UTF8 is shown below. I would really like to hear from those who know. PayPal tech doesn't seem to be able to go any further.

Am I even using the WebClient.encoding correctly? Because I have seen no change no matter what I change it to.
VB
Dim collection As New NameValueCollection
collection.Add("EMAIL", "name@domain.com")

Dim wc As New WebClient()
wc.Encoding = System.Text.Encoding.UTF8
Dim response As Byte() = wc.UploadValues(cURL, "POST", collection)
wc.Dispose()

'I have also tried:

'wc.Encoding = System.Text.Encoding.GetEncoding("ISO-8859-1")
'wc.Encoding = System.Text.Encoding.ASCII
'wc.Encoding = System.Text.Encoding.Default


This is something that just started about three to four days ago without any coding on my end.

"PS. I should mention that I am using PayPal hosted payment forms Layout "C" and am receiving error:
• Some required information is missing or incorrect. Please correct the fields below and try again.
• Error: Please enter a valid email address."

The error appears when the Credit card is submitted.
When the WebClient POST as shown above, I receive "RESULT=0&RESPMSG=Approved"

You would think the eMail would be rejected on the initial POST but it is not. The error only shows when I click on SUBMIT ORDER to send the CC numbers in the iFrame.

Thanks,
Posted
Updated 24-Nov-14 9:46am
v5

1 solution

Not sure it will help but here is a method I use for posting requests to a site, I have a PHP script that picks up the request and did have a few problems with character encoding.

Dim myRequester As WebRequest

Dim postData As String = Uri.EscapeUriString("<the data to send>")
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)

myRequester = WebRequest.Create("<your site url>")
myRequester.Method = "POST"
myRequester.ContentType = "application/x-www-form-urlencoded"
myRequester.ContentLength = byteArray.Length

Dim dataStream As Stream = myRequester.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()

Try
  response = CType(myRequester.GetResponse(), HttpWebResponse)
Catch ex As Exception
  response = CType(ex, System.Net.WebException).Response
End Try

If Response.StatusCode = HttpStatusCode.OK Then ...
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900