微软官方示例里的HTTPrequest借鉴
try
{
HttpResponseMessage response = await httpClient.PostAsync(resourceAddress,
new HttpStringContent(RequestBodyField.Text)).AsTask(cts.Token);
await Helpers.DisplayTextResultAsync(response, OutputField, cts.Token);
rootPage.NotifyUser("Completed", NotifyType.StatusMessage);
}
catch (TaskCanceledException)
{
rootPage.NotifyUser("Request canceled.", NotifyType.ErrorMessage);
}
catch (Exception ex)
{
rootPage.NotifyUser("Error: " + ex.Message, NotifyType.ErrorMessage);
}
finally
{
Helpers.ScenarioCompleted(StartButton, CancelButton);
}
还借用另外两个CS文件:Helpers.cs / PlugInFilter.cs
但是在生成response时抛出exception
HttpResponseMessage response = await httpClient.PostAsync(resourceAddress,
new HttpStringContent(RequestBodyField.Text)).AsTask(cts.Token);
09-25
在前期需要先定义变量
Helpers.CreateHttpClient(ref httpClient);
cts = new CancellationTokenSource();