[英]Cannot PUT/POST using Rest Sharp using XML
我想使用restSharp的PUT / POST方法在Redmine上創建/修改問題。 我無法使用Rest Sharp找到有關xml PUT / POST的有價值的信息。 我嘗試過restsharp.org中的各種方法,例如Addbody("test", "subject");
, IRestResponse response = client.Execute(request);
但是Redmine沒有任何變化。 我究竟做錯了什么?
POST給出“僅允許get, put和delete請求。” 信息。
PUT給出“僅允許get, post和delete請求”。 信息。
我的密碼
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);
您的代碼對我來說還可以,我不確定您是否需要此代碼,但在針對WebAPI主機使用REST的JSON時,我們添加了此標頭:
request.AddHeader("Accept", "application/xml");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.