【发布时间】:2015-02-12 18:16:58
【问题描述】:
我正在编写一个 Windows Phone 8.1 应用程序 (WINRT)。我创建了一个登录页面,并希望将登录数据发布到服务器并获得响应。
感谢@Kai Brummund,他为我提供了以下方法,但它使用旧的 System.Net.Http;但我想使用强烈推荐的 Windows.Web.Http.HttpClient
使用新的命名空间,在这个方法中到处都是错误。我需要做出哪些改变?
CancellationTokenSource cancellationToken;
public async void ReadHeaders()
{
cancellationToken = new CancellationTokenSource();
// Create the message
string address = singletonInstance.APIServer + "MkhAdapter/rest/mkh/Login";
var message = new HttpRequestMessage(HttpMethod.Post, new Uri(address));
// Add the message body
message.Content = new StringContent(
LoginJsonData,
System.Text.UTF8Encoding.UTF8, "application/json");
////filter/compress
//HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter();
// Send
var client = new HttpClient();
var result = await client.SendAsync(message, cancellationToken.Token);
result.EnsureSuccessStatusCode();
// Get ids from result
var finalresult = await result.Content.ReadAsStringAsync();
}
【问题讨论】:
-
有什么错误?
标签: c# windows-runtime httpwebrequest windows-phone-8.1 httpwebresponse