简体   繁体   中英

Restsharp XML request

I'm trying to PUT some data over an API with restsharp.

From the manual of the API, the PUT call is made using: template params id string barcode string

and

query params a string operator string c long

The request should have a custom header: Name = “Content-Type” Value = “application/xml”

Can someone tell me how to use restsharp to post a request like this?

Rest Sharp Put Custom Header , this helped me a lot the construction is like

request.RequestFormat = RestSharp.DataFormat.Xml;
request.XmlSerializer = newRestSharp.Serializers.DotNetXmlSerializer();
request.AddBody(x);  

was not working. But when I changed the code block body to

request.RequestFormat = RestSharp.DataFormat.Xml;
request.AddParameter("text/xml", x, ParameterType.RequestBody);

my solution began to work properly.

var client = new RestSharp.RestClient();
var request = new RestRequest(myUrl);
request.RequestFormat = DataFormat.Xml;

Should cause the content type and serialization to work correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM