Glebka
Glebka

Reputation: 1668

POST with WebRequest problem

This is the POST message to service of Google Chrome: This is the POST message to service of Google Chrome: I want post this POST message from C#:

System.Net.WebRequest req = 
System.Net.WebRequest.Create(@"http://www.ччч.ru/SystemService.asmx/VotingFoPhoto");
req.Method = "POST";
req.Timeout = 12000;
req.ContentType = "application/json; charset=UTF-8";

byte[] sentData = Encoding.GetEncoding(1251).GetBytes("photoId=E6A0327A&concursId=3");
req.ContentLength = sentData.Length;
System.IO.Stream sendStream = req.GetRequestStream();
sendStream.Write(sentData, 0, sentData.Length);
sendStream.Close();

req.GetResponse();

When i run this code, i get 500 server error. Help me please.

Upvotes: 2

Views: 853

Answers (1)

Ben
Ben

Reputation: 35613

You have told the server your content-type is application/json. But you have provided content in application/x-www-urlencoded format.

Try providing JSON format:

byte[] sentData = 
  Encoding.GetEncoding(1251).GetBytes("{'photoId':'E6A0327A';'concursId':3}"); 

Alternatively try changing the content-type header.

Upvotes: 3

Related Questions