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);
Conrad C
  • 746
  • 1
  • 11
  • 32
  • At least explain why you downvote this post. – Conrad C Nov 14 '12 at 18:44
  • Conrad look at this StackOverFlow link http://stackoverflow.com/questions/10747261/how-to-add-a-get-parameter-to-a-post-request-with-restsharp if this doesn't help do a google search on C# Put/GET RestSharp example – MethodMan Nov 14 '12 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. – Conrad C Nov 14 '12 at 18:47
  • If you are wanting to do this with XML you may want to change your question to reflect this.. – MethodMan Nov 14 '12 at 18:50
  • here is another link ..if you have XML also show the structure of the XML please.. http://stackoverflow.com/questions/8917437/posting-to-a-rest-service-with-restsharp – MethodMan Nov 14 '12 at 18:54
  • @DJKRAZE , The link you sent is not related to my problem. Please tell me if something is unclear. – Conrad C Nov 14 '12 at 19:03
  • are you trying to do this using XML..? I am a bit confused based on one of your comments.. thanks – MethodMan Nov 14 '12 at 19:05
  • Can you post on how the REST method looks like to help you out. – Rajesh Nov 15 '12 at 10:29
  • Or perhaps both the request and response from Fiddler might help? – C.M. Nov 15 '12 at 14:38

2 Answers2

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);
Conrad C
  • 746
  • 1
  • 11
  • 32
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");
C.M.
  • 1,474
  • 13
  • 16