HttpClient httpClient = new HttpClient();
try
{
string login_url = config.server_host+"/user/login";
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post,new Uri(login_url));
var postData = new HttpFormUrlEncodedContent(new List<KeyValuePair<string, string>> {
new KeyValuePair<string,string>("username",name),
new KeyValuePair<string,string>("password",pwd),
});
request.Content = postData;
HttpResponseMessage response = await httpClient.SendRequestAsync(request);
string responseString = await response.Content.ReadAsStringAsync();
this.output(responseString);
}
catch(Exception ex)
{
this.output(ex.Message.ToString());
}
output函数
void output(string content)
{
await new MessageDialog(content).ShowAsync();
}