2011-09-14 58 views
2

這是POST消息,谷歌Chrome瀏覽器的服務: This is the POST message to service of Google Chrome: 我想從C#發佈此POST消息:POST與WebRequest的問題

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(); 

當我運行這段代碼,我得到500服務器錯誤。請幫幫我。

+1

鏈接http://www.ччч.ru/SystemService.asmx/VotingFoPhoto無效 –

+0

這是最常見的http錯誤信息,請查看http://stackoverflow.com/questions/4098945/500-我知道內部服務器錯誤在答覆 – 62071072SP

+0

。這是例如。 – GLeBaTi

回答

3

你已經告訴服務器你的content-typeapplication/json。但您提供的內容格式爲​​。

嘗試提供JSON格式:

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

可選擇地嘗試改變該內容 - 類型報頭。