0
我在c#中有一個代碼,但是我得到下一個錯誤:「(400)不正確的請求」。在REST API中插入HP ALM的要求#c#
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();
「400」 是一個HTTP錯誤,這是由服務器在 「myURL」 返回。所以這取決於Web服務期望的內容,以及這與您發送的內容有什麼不同。 –
您應該創建一個CookieContainer並將其分配給您執行的每個Web請求。您在這裏複製cookie的方式是失敗的祕訣。還要安裝一個本地代理,如fiddler,以便您可以調試http請求。 – rene