简体   繁体   中英

Insert requirement in HP ALM with REST API and c#

I have a code in c#, but I get the next error: "(400) incorrect request".

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();

I get the error in the line webResponse = (HttpWebResponse)myWebRequest2.GetResponse();

Regarding the Create an Entity documentation , there are some problems with JSON structure that you are trying to send.

This structure

{
  "Fields":[{
      "Name":"type-id",
      "values":[{"value":"3"}]
    },{
      "Name":"name",
      "values":[{"value":"MyPrueba"}]
    }]
}

should be used instead of this one

{
  "type-id":3,
  "name":"MyPrueba"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM