【问题标题】:POST with WebRequest problemPOST 与 WebRequest 问题
【发布时间】:2011-11-17 01:22:24
【问题描述】:

这是 Google Chrome 服务的 POST 消息: 我想从 C# 发布这条 POST 消息:

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 服务器错误。请帮帮我。

【问题讨论】:

标签: c# .net asp.net post


【解决方案1】:

你已经告诉服务器你的content-typeapplication/json。但是你提供了application/x-www-urlencoded格式的内容。

尝试提供 JSON 格式:

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

或者尝试更改内容类型标头。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-02
    • 1970-01-01
    • 2020-11-09
    • 1970-01-01
    • 1970-01-01
    • 2016-03-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多