Forums » Development »
Post Relations with Json
Added by Andreas Danzer over 11 years ago
I try to update the relations via Json. But I don´t get the format right. I´m using C#. I got 402 Exception, wrong Format.
Thanks for any help.
Here my Code:
var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://" + Constants.REDMINE_HOST + "/" + Constants.REDMINE_SERVER + "/" + "issues/" + id + "/relations" + ".json" + "?key=Constants.mykey"); httpWebRequest.ContentType = "text/json"; httpWebRequest.Method = "POST"; httpWebRequest.Accept = "application/json"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = "{relation: {\"issue_to_id\" : 499 \"relation_type\" : \"relates\"}}"; streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); try { var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); } } catch(Exception e) { Console.WriteLine(e); }
Replies (4)
RE: Post Relations with Json - Added by Etienne Massip over 11 years ago
httpWebRequest.ContentType = "text/json";
(...)
httpWebRequest.Accept = "application/json";
Why is ContentType set to text/jon
??
RE: Post Relations with Json - Added by Andreas Danzer over 11 years ago
When is set the contentType to application/json i got:
The remote server returned an error: (500) Internal Server Error.
and with text/json
it says:
The remote server returned an error: (422) Unprocessable Entity.
So it looks this is the right way, only the string content is wrong or?
Thank you!
RE: Post Relations with Json - Added by Etienne Massip over 11 years ago
application/json
is the right value, check your production.log
file to get the 500 server error reason.
RE: Post Relations with Json - Added by Andreas Danzer over 11 years ago
okay thank you, I don´t have access to the logs because the admin is on holiday.
Maybe someone can see the problem with one look.