https://monkeyweekend.wordpress.com/2014/10/23/how-to-send-text-json-or-files-using-httpclient-postasync/

using Windows.Web.Http;

using Windows.Data.Json;

//post request

Windows.Web.Http.HttpClient oHttpClient = new Windows.Web.Http.HttpClient();

Uri uri = new Uri("https://www.abc.com/testapi");
string contentBody = "the data you want to post";

HttpRequestMessage mSent = new HttpRequestMessage(HttpMethod.Post, uri);
mSent.Content =new HttpStringContent(String.Format("{0}", contentBody), Windows.Storage.Streams.UnicodeEncoding.Utf8);

HttpResponseMessage mReceived = await oHttpClient.SendRequestAsync(mSent, HttpCompletionOption.ResponseContentRead);

 

//read reponse to json string

string jsonStr = await mReceived.Content.ReadAsStringAsync();

//parse json

JsonValue jsonValue = JsonValue.Parse(jsonStr);

string bruid = jsonValue.GetObject().GetNamedString("someKey");

posted on 2015-06-04 14:08  ximenchuixie  阅读(220)  评论(0编辑  收藏  举报