1

我想使用 restSharp 的 PUT/POST 方法在 redmine 上创建/修改问题。我无法使用 Rest sharp 找到有关 xml PUT/POST 的有价值信息。我尝试了来自 restsharp.org 的各种方法 Addbody("test", "subject");IRestResponse response = client.Execute(request);但 Redmine 没有任何变化。我究竟做错了什么?

POST 给出“仅允许获取、放置和删除请求”。信息。

PUT 给出“仅允许获取、发布和删除请求”。信息。

我的代码

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

2 回答 2

1

问题出在序列化中。我的Issue类包含导致序列化问题的各种其他类的对象。这就是我们的做法:

    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);
于 2012-11-15T18:14:38.770 回答
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");
于 2012-11-14T19:22:05.153 回答