1
我正在做一个HTTP“PUT”使用WebClient类JSON字符串到弹性搜索。该代码适用于95%的案例,但其余部分失败。我得到的错误是我的代码中有400个错误的协议。当我使用jQuery AJAX或名为Postman的Chrome扩展发布相同的JSON时,它可以完美地工作。我不知道如何解决这个错误。我的代码如下 -NET WebClient 400错误
string json = "{some json}";
WebClient client = new WebClient();
client.Headers["Content-Type"] = "application/json;charset=UTF-8";
try
{
json = client.UploadString(URL, "PUT", json);
}
catch (WebException ex)
{
//catch exception
}