我在c#中有一个代码,但是我收到了下一个错误:"(400)错误的请求"。
HttpWebRequest myWebRequest2 = (HttpWebRequest)WebRequest.Create("http://myURL/qcbin/rest/domains/DEFAULT/projects/Mercury/requirements");
myWebRequest2.Method = "POST";
myWebRequest2.Accept = "application/json";
myWebRequest2.ContentType = "application/json";
myWebRequest2.CookieContainer = new CookieContainer();
myWebRequest2.CookieContainer.Add(webResponse.Cookies[0]);
myWebRequest2.CookieContainer.Add(webResponse.Cookies[1]);
myWebRequest2.CookieContainer.Add(webResponse.Cookies[2]);
myWebRequest2.CookieContainer.Add(webResponse.Cookies[3]);
StreamWriter streamWriter = new StreamWriter(myWebRequest2.GetRequestStream());
string json = "{ \"type-id\": 3,\"name\": \"MyPrueba\"}";
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
webResponse = (HttpWebResponse)myWebRequest2.GetResponse();
我在第webResponse = (HttpWebResponse)myWebRequest2.GetResponse();
行
答案 0 :(得分:0)
关于Create an Entity documentation,您尝试发送的JSON结构存在一些问题。
这个结构
{
"Fields":[{
"Name":"type-id",
"values":[{"value":"3"}]
},{
"Name":"name",
"values":[{"value":"MyPrueba"}]
}]
}
应该使用代替这个
{
"type-id":3,
"name":"MyPrueba"
}