public static async Task<string> GetData(string url, string data)
{
UriBuilder fullUri = new UriBuilder(url);
if (!string.IsNullOrEmpty(data))
fullUri.Query = data;
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.PostAsync(new Uri(url), /*expects HttpContent*/);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
return responseBody;
}
Run Code Online (Sandbox Code Playgroud)
将PostAsync采取一个需要另一个参数HttpContent.
我该如何设置HttpContent?任何适用于Windows Phone 8的文档都没有.
如果我这样做GetAsync,那就太棒了!但它需要POST的内容为key ="bla",某事="yay"
//编辑
非常感谢答案......这很有效,但这里还有一些不确定的地方:
public static async Task<string> GetData(string url, string data)
{
data = "test=something";
HttpClient client = new HttpClient();
StringContent queryString …Run Code Online (Sandbox Code Playgroud)