1
votes

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?

2

2 Answers

11
votes

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.

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

Should cause the content type and serialization to work correctly.