Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to post XML data via HTTP POST method in windows store apps?

Any samples on consuming rest service post method in windows 8 apps.Please let me know the possible links on that.

like image 688
user1237131 Avatar asked Feb 16 '23 11:02

user1237131


1 Answers

Try this

using System.IO;
using System.Net.Http;
using System.Text;

var objHttpClient = new HttpClient();
var formParameters = "<details><id>1</id><name>test</name></details>");
var objHttpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "http://example.com/page");
objHttpRequestMessage.Content = new StreamContent(new MemoryStream(Encoding.UTF8.GetBytes(formParameters)));
objHttpRequestMessage.Content.Headers.Add("Content-Type", "text/xml");
var result = await objHttpClient.SendAsync(objHttpRequestMessage);

Also check HttpClient sample on MSDN

like image 187
Farhan Ghumra Avatar answered May 01 '23 10:05

Farhan Ghumra