473,790 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 NameValueCollec tion and then sent it using
WebClient.Uploa dValues.
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 myNameValueColl ection As New NameValueCollec tion()

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.
myNameValueColl ection.Add("TEX T", MYTEXT)
myNameValueColl ection.Add("USE R", USER)

'The Upload(String,N ameValueCollect ion)' method implicitly
sets the HTTP POST as the request method.
myWebClient.Cre dentials =
Net.CredentialC ache.DefaultCre dentials

responseArray = myWebClient.Upl oadValues(uriSt ring,
myNameValueColl ection)

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

Feb 18 '07 #1
3 8394
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.Heade rs.Add("CharSet ", "UTF-8"); // or
webClient.Heade rs.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.Unicod e.GetString(res ponse)

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 NameValueCollec tion and then sent it using
WebClient.Uploa dValues.
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 myNameValueColl ection As New NameValueCollec tion()

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.
myNameValueColl ection.Add("TEX T", MYTEXT)
myNameValueColl ection.Add("USE R", USER)

'The Upload(String,N ameValueCollect ion)' method implicitly
sets the HTTP POST as the request method.
myWebClient.Cre dentials =
Net.CredentialC ache.DefaultCre dentials

responseArray = myWebClient.Upl oadValues(uriSt ring,
myNameValueColl ection)

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

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.Heade rs.Add("CharSet ", "UTF-8"); // or
webClient.Heade rs.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.Enc oding = System.Text.Enc oding.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.Heade rs.Add("CharSet ", "UTF-8"); // or
webClient.Heade rs.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.Enc oding = System.Text.Enc oding.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
5369
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
13305
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 = "application/octet-stream"; Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileID.ToString() + ".pdf");
0
1480
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 system. I don't want to use the input file method (as this will force the user to do unnessecary browsing and I know where the file will be: c:\test.txt for example). I am sure that I am just missing something simple. However, I can not figure...
0
4089
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 System.Net.WebClient web.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
6
22107
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 (setup.exe). I then use WebClient.DownloadFileAsync (.NET 2.0 Pro.) and all downloads well including progress bar indicator, bytes received, etc... Here is the problem: When I replace the file (setup.exe), with a different, larger file, it still...
2
1257
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) However I understand that IE no longer supports this 'in-line' presentation of the username and password strings. Indeed I am getting a "Not Authorized" error being returned.
1
6496
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 <authentication mode="Windows" /> and set up IIS to not allow anonymous access. My browser is set up to auto detect the proxy server, so IE/Firefox can access outside pages, so I added code to auto-detect the proxy server.
3
11047
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 NetworkCredential();
3
1558
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. The web service will upload to the FTP site 12 times. The 13th time it will timeout. Once the web service is reset - that is
0
9512
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10413
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10145
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9021
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7530
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5422
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4094
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.