C# 对https站点的PUT请求持续返回状态:400错误请求

C# 对https站点的PUT请求持续返回状态:400错误请求,c#,http,http-headers,xmlhttprequest,put,C#,Http,Http Headers,Xmlhttprequest,Put,我试图用c中的httpWebRequest向plug.dj发出一个PUT请求,问题是我一直收到错误400bad请求,但我发出的请求看起来与原来的请求相同,我是不是搞错了什么 这些是我在进入网络选项卡时从chrome获得的请求头: PUT /_/booth/lock HTTP/1.1 Host: plug.dj Connection: keep-alive Content-Length: 39 Accept: application/json, text/javascript, */*; q=0.

我试图用c中的httpWebRequest向plug.dj发出一个PUT请求,问题是我一直收到错误400bad请求,但我发出的请求看起来与原来的请求相同,我是不是搞错了什么

这些是我在进入网络选项卡时从chrome获得的请求头:

PUT /_/booth/lock HTTP/1.1
Host: plug.dj
Connection: keep-alive
Content-Length: 39
Accept: application/json, text/javascript, */*; q=0.01
Origin: https://plug.dj
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36
Content-Type: application/json
Referer: https://plug.dj/ao3
Accept-Encoding: gzip, deflate, sdch
Accept-Language: nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4
Cookie: {Left out becouse it's used to authenticate}
请求有效负载和请求Url:

{"isLocked":true,"removeAllDJs":false}
https://plug.dj/_/booth/lock
这是我在c中使用HttpWebRequest创建的身份验证是正确的,所以这不是错误:

var httpWebRequest = (HttpWebRequest)WebRequest.Create(requestUrl);
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "PUT";

httpWebRequest.Accept                           = "application/json, text/javascript, */*; q=0.01";
httpWebRequest.Headers["Accept-Encoding"]       = "gzip, deflate, sdch";
httpWebRequest.Headers["Accept-Language"]       = "nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4";
httpWebRequest.ContentLength                    = data.Length;
httpWebRequest.Headers["Cookie"]                = GetCookies();
httpWebRequest.Host                             = "plug.dj";
httpWebRequest.Headers["Origin"]                = "https://plug.dj";
httpWebRequest.Referer                          = "https://plug.dj/" + _room;
httpWebRequest.UserAgent                        = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36";
httpWebRequest.Headers["X-Requested-With"]      = "XMLHttpRequest";

using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
    streamWriter.Write(data);
}

var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
    return streamReader.ReadToEnd();
}

尝试使用Fiddler查看来自您的c程序的请求是什么样子的。我尝试使用Fiddler@MårtenWikströM,当我运行程序时,Fiddler:CONNECT plug.dj:443 HTTP/1.1中显示了这一点。之后,在我的c代码中,错误:底层连接已关闭:无法为SSL/TLS安全通道建立信任关系。编辑:当我消除ssl错误时,我再次获得状态400:Bad请求。。ServicePointManager.ServerCertificateValidationCallback=委托对象发送方,X509Certificate证书,X509Chain链,SslPolicyErrors SslPolicyErrors{return true;};请尝试使用HTTP而不是HTTPS,或者在Fiddler中启用对HTTPS通信的解密支持:使用HTTP不起作用,并且解密时出错:证书不受信任,因为未提供颁发者链。我真的没有使用sslOk的经验。我认为看到你的c程序发送的请求,并将其与Chrome的请求进行比较,是找出你收到400个错误请求的关键。但是,我恐怕无法帮助您在Fiddler中配置SSL解密,因为我自己从来没有这样做过。