c# - 无法使用 XML 使用 Rest Sharp PUT/POST

标签 c# xml http rest restsharp

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

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

最佳答案

问题出在序列化中。我的 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);

关于c# - 无法使用 XML 使用 Rest Sharp PUT/POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13385206/

相关文章:

java - Intellij插件: Intention for xml file that replace an attribute with two custom attribute with different prefix with same value

http - HTTP 请求至少需要什么?

c# - 无法加载文件或程序集 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

c# - 如何静态声明一个对象数组

c# - 我正在尝试学习如何将 IEnumerable LINQ 集合绑定(bind)到转发器

javascript - 如何在javascript(ajax)中使用嵌入HTML中的XML数据?

c# - 类属性的 Lambda 表达式

java - checkstyle 配置期间失败 : unable to parse configuration stream

javascript - 从数据库获取数据到angular js

java - 运行时或事务 Controller 或其他东西?