当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Windows Phone 8 HttpClient and POSTing JSON

问题描述:

I am quite new to C# and WP8 in general. I am currently finding difficulties in doing a simple POST to web service and retrieving the answer. All is done via JSON.

So far I managed to write this:

 public async static Task<string> SendJSONData(string urlToCall, string JSONData)

{

HttpClient client = new HttpClient();

try

{

HttpResponseMessage response = await client.PostAsync(urlToCall, new StringContent(JSONData.ToString(),Encoding.UTF8,"application/json"));

string res = response.Content.ReadAsStringAsync().Result;

return res;

}

catch

{

// error catching...

}

But obviously no luck and I am pretty sure is bad. Thus I am unable to find any proper documentation on that.

In fact I am not sure it sends the POST in the right way and what I get from that "return res" is: System.Threading.Tasks.Task`1[System.String]

The idea as said is to send a JSON array and to retrieve one from the same URL.

Thank you all for your help!

分享给朋友:
您可能感兴趣的文章:
随机阅读: