1

I want to create/modify an issue on redmine using the PUT/POST methods of restSharp. I cannot find valuable information about xml PUT/POST using Rest sharp. I tried various methods from restsharp.org like Addbody("test", "subject"); , IRestResponse response = client.Execute(request); but there is no change in Redmine. What am I doing wrong?

POST gives a "Only get, put, and delete requests are allowed." message.

PUT gives a "Only get, post, and delete requests are allowed." message.

My Code

    RestClient client = new RestClient(_baseUrl);
    client.Authenticator = new HttpBasicAuthenticator(_user, _password);


    RestRequest request = new RestRequest("issues/{id}.xml", Method.POST);

    request.AddParameter("subject", "Testint POST");

    request.AddUrlSegment("id", "5");


    var response = client.Execute(request);
9
  • At least explain why you downvote this post. Commented Nov 14, 2012 at 18:44
  • Conrad look at this StackOverFlow link stackoverflow.com/questions/10747261/… if this doesn't help do a google search on C# Put/GET RestSharp example Commented Nov 14, 2012 at 18:46
  • I did, and the only examples given are in JSON not xml, I also tried to adapt their example to xml, and it still gives no change in redmine. Commented Nov 14, 2012 at 18:47
  • If you are wanting to do this with XML you may want to change your question to reflect this.. Commented Nov 14, 2012 at 18:50
  • here is another link ..if you have XML also show the structure of the XML please.. stackoverflow.com/questions/8917437/… Commented Nov 14, 2012 at 18:54

2 Answers 2

1

The problem was in the serialization. My Issue class contains object of various other classes which was causing a problem in the serialization. This is how we did it:

    RestRequest request = new RestRequest("issues/{id}.xml", Method.PUT);
    request.AddParameter("id", ticket.id, ParameterType.UrlSegment);
    request.XmlSerializer = new RedmineXmlSerializer();
    request.AddBody(ticket);

    RestClient client = new RestClient(_baseUrl);
    client.Authenticator = new HttpBasicAuthenticator(_user, _password);
    IRestResponse response = client.Execute(request);
Sign up to request clarification or add additional context in comments.

Comments

0

Your code looks ok to me, I'm unsure if you need this but we added this header when using RestSharp for json against a WebAPI host:

        request.AddHeader("Accept", "application/xml");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.