JSON C#WebRequest返回错误400错误请求
以下代码在请求时引发错误。GetResponse()。它返回错误400错误请求。我尝试了不同的方法,但至今没有成功。我能做些什么来获得关于错误400的更多细节吗JSON C#WebRequest返回错误400错误请求,c#,json,httpwebrequest,C#,Json,Httpwebrequest,以下代码在请求时引发错误。GetResponse()。它返回错误400错误请求。我尝试了不同的方法,但至今没有成功。我能做些什么来获得关于错误400的更多细节吗 string sURL = "https://testservice.mywebsite.be/games/1/players"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sURL); request.Method = "POS
string sURL = "https://testservice.mywebsite.be/games/1/players";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sURL);
request.Method = "POST";
request.Accept = "application/json";
request.ContentType = "application/json";
String sTimestamp = DateTime.Now.ToUniversalTime().ToString("yyyyMMddHHmmss");
string sHMACmessage = string.Format("verb={0}×tamp={1}&url={2}&playernumber={3}", request.Method.ToString().ToUpperInvariant(), sTimestamp, sURL, sPlayerNumber);
byte[] bHash = HashHMAC(StringEncode("myprivatekey"), StringEncode(sHMACmessage));
string sHash = HashEncode(bHash);
request.Headers.Add("Timestamp", sTimestamp);
request.Headers.Add("PlayerNumber", sPlayerNumber);
request.Headers.Add("Authentication", String.Concat("mypublickey", ":", sHash));
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
string json = "{\"playingYear\":\"2015\"}";
streamWriter.Write(json);
}
long length = 0;
try
{
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
length = response.ContentLength;
}
}
catch (WebException ex)
{
throw;
}
在testservice中,确保关闭以下选项以查看详细错误:
<?xml version="1.0"?>
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
在尝试使用代码之前,还可以尝试使用类似的工具,看看它是否可以从那里工作。在testservice中,确保关闭以下选项以查看详细错误:
<?xml version="1.0"?>
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
在尝试使用代码之前,还可以尝试使用类似的工具,看看它是否在那里工作。URL正确吗?它返回一个400 not found…是的,对于其他内部连接,它工作得很好。另外,您根本不使用sHMACmessage,这些参数是否应该发送到服务器?使用sHMACmessage,对其进行哈希处理,并将其添加到名为“authentication”的json头中确保您的服务接受HttpPost…URL正确吗?它返回一个400 not found…是的,对于其他内部连接,它工作正常。另外,您根本不使用sHMACmessage,这些参数是否应该发送到服务器?使用sHMACmessage时,将对其进行哈希处理并添加到名为“authentication”的json头中确保您的服务接受HttpPost。。。