I'm developing a software who call API and I have to send to this API a request on XML to get more data.
I have allready tried request.AddXmlBody(nextID)
but it doesn't work, I have also tried request.AddParameter("text/xml", nextID, ParametreType.RequestBody )
and I get an error : XML exception, root element is missing.
var client = new RestClient("https://xxxxxxxxxxxxx.xxx");
client.Authenticator = new HttpBasicAuthenticator("xxxxx", "xxxx");
var request = new RestRequest("/xx/xxx/xx/xx/xxxxx", Method.GET);
string nextID = "<?xml version=\"1.0\" encoding=\"UTF - 8\" ?>< ServiceRequest > < filters > < Criteria field = \"id\" operator= \"GREATER\" > 13782472 </ Criteria ></ filters ></ ServiceRequest > ";
request.AddHeader("X-Requested-With", "RestSharp");
request.AddParameter(nextID);
IRestResponse response = client.Execute(request);
var xml_text = response.Content;
string xq1 = "//*[contains(text(),'XXX')]/..";
XmlDocument xd = new XmlDocument();
xd.LoadXml(xml_text);
I want to add my string nextID
to the body of my request to get the file I want.
Thank's to @jdweng, my extra space on my string was my mistake.
This code works :
string nextID = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ServiceRequest> <filters> <Criteria field = \"id\" operator=\"GREATER\"> 13782472 </Criteria></filters></ServiceRequest>";
request.AddHeader("X-Requested-With", "RestSharp");
request.AddParameter("text/xml", nextID, ParameterType.RequestBody);
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.