Asked by:
Consume xml input

Question
-
User-148788041 posted
Hi
I am able to consume json input string in Httpclient.can Httpclient be used to consume xml input string.please provide example for put,post,delete, options,head and merge.
Friday, June 21, 2019 1:38 PM
All replies
-
User753101303 posted
Hi,
Avoid asking too many things with not much details and focus rather on a first point before moving to the next. So you are the PostAsJsonAsync extension method ?
You have also https://docs.microsoft.com/en-us/previous-versions/aspnet/hh944689(v%3Dvs.118) ie PostAsXmlAsync. Depending on what you have done on the server side it should be the main if not the only change. Let's try to have an XML POST request to work maybe before moving to the next issue ?
Friday, June 21, 2019 2:36 PM -
User1120430333 posted
Hi
I am able to consume json input string in Httpclient.can Httpclient be used to consume xml input string.please provide example for put,post,delete, options,head and merge.
You would have to change the content negotiation that the WebAPI was sending and that the HTTPClient is expecting.
https://www.codeproject.com/Articles/1110659/Formatters-and-Content-Negotiation-in-ASP-NET-Web
Sunday, June 23, 2019 2:44 AM -
User61956409 posted
Hi Guhananth,
You can refer to the following API and example request.
API action
public void Post([FromBody]TestObj value) { //code logic here }
TestObj class
public class TestObj { public string Name { get; set; } public int Age { get; set; } }
Example request
using (var httpClient = new HttpClient()) { var uri = new Uri("http://xxxx/api/values"); var XML = "<TestObj><Name>TestUser</Name><Age>25</Age></TestObj>"; var httpContent = new StringContent(XML, Encoding.UTF8, "text/xml"); var response = await httpClient.PostAsync(uri, httpContent); }
Test Result
With Regards,
Fei Han
Monday, June 24, 2019 5:42 AM -
User-1038772411 posted
Hello Guhananth,
Kindly refer the below link , I hope this will help you
It is providing example for put, post, delete etc with description.
https://www.c-sharpcorner.com/UploadFile/dacca2/http-request-methods-get-post-put-and-delete/
Thank you.
Monday, June 24, 2019 7:45 AM