473,327 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

problems with WebClient

Hi!
I need to pass some strings via an HTTP POST from page1 (in my app) to
a page on another server.
I stored my data in a NameValueCollection and then sent it using
WebClient.UploadValues.
Everything works fine but if one of the string contains a european
character (èéòàù...) it's not sent correctly and the char is received
as a '?'
I read at least 20 different posts on similiar problem but didn't find
a solution yet.
any help?

Giggi

This is the code:

Dim uriString As String = "http://aqua.altervista.org/
prova.php"
Dim myWebClient As New Net.WebClient()
Dim myNameValueCollection As New NameValueCollection()

Dim MYTEXT As String = TextBox1.Text
Dim USER As String = TextBox2.Text

Dim responseArray As Byte()
Dim answer As String

' Add necessary parameter/value pairs to the name/value
container.
myNameValueCollection.Add("TEXT", MYTEXT)
myNameValueCollection.Add("USER", USER)

'The Upload(String,NameValueCollection)' method implicitly
sets the HTTP POST as the request method.
myWebClient.Credentials =
Net.CredentialCache.DefaultCredentials

responseArray = myWebClient.UploadValues(uriString,
myNameValueCollection)

'Decode the response.
answer= Encoding.ASCII.GetString(responseArray)

Feb 18 '07 #1
3 8337
Howdy Giggi,

It's happening because your PHP page uses 'ISO 8859-1' code page. Characters
that cannot be recognised are automatically translated to 0x63 which is
equivalent to '?' in ISO 8859-1. Because ASP.NET works in Unicode by default,
WebClient does not send encoding information in outgoing POST
application/x-www-form-urlencoded request (if you create an empty page in
ASP.NET and request it in your code instead of php page, all characters will
be properly decoded). Therefore 'prova.php' page is unable to decode incoming
requests properly. I reckon you would have to amend your php page to handle
and serve unicode request. In addtion to that, request encoding can be
specified by adding charset header before calling UploadValues:

webClient.Headers.Add("CharSet", "UTF-8"); // or
webClient.Headers.Add("Charset", "text/html; charset=UTF-8");

Remember if you change request encoding to ASCII it won't help you with
european characters because they are handled differently than ISO 8859-1.
After you sort out PHP page, also remember to use Unicode/UTF8 in vb.net code

answer = Encoding.Unicode.GetString(response)

Hope it helps
--
Milosz
"Giggi" wrote:
Hi!
I need to pass some strings via an HTTP POST from page1 (in my app) to
a page on another server.
I stored my data in a NameValueCollection and then sent it using
WebClient.UploadValues.
Everything works fine but if one of the string contains a european
character (èéòÃ*ù...) it's not sent correctly and the char is received
as a '?'
I read at least 20 different posts on similiar problem but didn't find
a solution yet.
any help?

Giggi

This is the code:

Dim uriString As String = "http://aqua.altervista.org/
prova.php"
Dim myWebClient As New Net.WebClient()
Dim myNameValueCollection As New NameValueCollection()

Dim MYTEXT As String = TextBox1.Text
Dim USER As String = TextBox2.Text

Dim responseArray As Byte()
Dim answer As String

' Add necessary parameter/value pairs to the name/value
container.
myNameValueCollection.Add("TEXT", MYTEXT)
myNameValueCollection.Add("USER", USER)

'The Upload(String,NameValueCollection)' method implicitly
sets the HTTP POST as the request method.
myWebClient.Credentials =
Net.CredentialCache.DefaultCredentials

responseArray = myWebClient.UploadValues(uriString,
myNameValueCollection)

'Decode the response.
answer= Encoding.ASCII.GetString(responseArray)

Feb 19 '07 #2
It's happening because your PHP page uses 'ISO 8859-1' code page. Characters
that cannot be recognised are automatically translated to 0x63 which is
equivalent to '?'
[CUT]
request encoding can be
specified by adding charset header before calling UploadValues:

webClient.Headers.Add("CharSet", "UTF-8"); // or
webClient.Headers.Add("Charset", "text/html; charset=UTF-8");
Hi Milosz!
Thank you very much for the answer,
I tried to add the charset header but it doesn't work. I also tried to
add:

myWebClient.Encoding = System.Text.Encoding.UTF8

The php page still receives ? instead of the european character.
But the real problem is that the PHP page is a page I created for
testing purpose in order to read what an external page receives from
my HTTP POST. The real external page is a classic .ASP page that allow
me to send an SMS.
Any other idea? Should I use httpwebrequest instead?

Giggi

Feb 19 '07 #3
Good morning Giggi,

As i suggested in previous reply the problem is your test PHP page. Whatever
encoding you set in webclient or webrequest classes instance, prova.php
always treats incoming request as 'ISO 8859-1' encoded. I created a test
classic ASP page, and everything is working like a charm. I haven’t used PHP
in my life so I have no idea what needs to be done to support Unicode
characters. Anyway, you said sms sending page is a classic ASP page, so
shouldn’t you create a test ASP page as a testing eniroment?

Hope this helps
--
Milosz
"Giggi" wrote:
>
It's happening because your PHP page uses 'ISO 8859-1' code page. Characters
that cannot be recognised are automatically translated to 0x63 which is
equivalent to '?'
[CUT]
request encoding can be
specified by adding charset header before calling UploadValues:

webClient.Headers.Add("CharSet", "UTF-8"); // or
webClient.Headers.Add("Charset", "text/html; charset=UTF-8");

Hi Milosz!
Thank you very much for the answer,
I tried to add the charset header but it doesn't work. I also tried to
add:

myWebClient.Encoding = System.Text.Encoding.UTF8

The php page still receives ? instead of the european character.
But the real problem is that the PHP page is a page I created for
testing purpose in order to read what an external page receives from
my HTTP POST. The real external page is a classic .ASP page that allow
me to send an SMS.
Any other idea? Should I use httpwebrequest instead?

Giggi

Feb 19 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: xzzy | last post by:
I have .net 1.1 c# . . . . . using System.Net only lists sockets what do I need to do to be able to do: using System.Net.WebClient;
6
by: A.M-SG | last post by:
Hi, I have an aspx page at the web server that provides PDF documents for smart client applications. Here is the code in aspx page that defines content type: Response.ContentType =...
0
by: David W | last post by:
I am trying to upload a file from a user's system to my web server. I found code using the WebClient.UploadFile method. However, the uploaded file is from the server's hard drive not the user's...
0
by: Kumar | last post by:
Hi all, I have the following code which uses WebClient.UploadValues myNameValueCollection.Add("Name", name) myNameValueCollection.Add("Age", age) .............. ............. Dim web As New...
6
by: Giovanni | last post by:
Hi Guys, Really strange problem I am experiencing... I have setup a virtual directory with Read Only permissions on an ISA/IIS server (SBS 2003). In that virt. dir., I placed 1 file...
2
by: Jerry Spence1 | last post by:
I am trying to get a jpg image as follows: Dim Client As System.Net.WebClient = New System.Net.WebClient Client.DownloadFile("http://root:<password>@192.168.0.99/cgi-bin/video.jpg", MyFilename)...
1
by: Mad Scientist Jr | last post by:
For some reason I can't get a WebClient to access an outside URL from behind our firewall. The code works when it runs outside the firewall. I turned on windows authentication in the web.config...
3
by: df | last post by:
Hi, I'm trying to download the web page source code from a HTTPS URL, my code is as follows: Code: System.Net.WebClient WC = new System.Net.WebClient(); NetworkCredential Cred = new...
3
by: kpg | last post by:
(Multi-post from microsoft.public.dotnet.framework.aspnet.webservices, Please apply all applicable pardons.) Hi all, I have a web service that FTPs data it receives to a third party FTP site....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.