Chris
Chris

Reputation: 805

c# webclient upload and download data from ssl

I have a wamp server on windows. SSL configured correctly. In browser it is working threw https: . I have a script test.php and I want to download and upload some POST data to it. I have my c# code:

WebClient client = new WebClient();
client.Encoding = Encoding.UTF8;
NameValueCollection values = new NameValueCollection();
values.Add("paramtest", "testval");
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
byte[] result;   
result = client.UploadValues("https://127.0.0.1./test.php", "POST", values); 
string htmlCode = Encoding.UTF8.GetString(result);
textBox1.Text = htmlCode;

When runnign this code with http I got all the data. When put https, I got an error from the server:

400 Bad Request

Bad Request

Your browser sent a request that this server could not understand.

Have you got any idea how can I fix it?

Upvotes: 0

Views: 2427

Answers (1)

Jens Meinecke
Jens Meinecke

Reputation: 2940

Not sure whether this is the cause, but your url has a trailing '.' after the IP address:

try

result = client.UploadValues("https://127.0.0.1/test.php", "POST", values);

instead of

result = client.UploadValues("https://127.0.0.1./test.php", "POST", values);

Upvotes: 3

Related Questions