private async Task<string> HttpRequestAsync(Func<Task<string>> httpRequestFuncAsync, Action<String> Change, Action Wait,int flag)
{
string responseBody;
try
{
responseBody = await httpRequestFuncAsync();
cts.Token.ThrowIfCancellationRequested();
}
catch (TaskCanceledException)
{
responseBody = "请求被取消";
throw new Exception();
}
catch (Exception ex)
{
responseBody = "错误信息:" + ex.Message;
if (responseBody.Contains("HRESULT"))
responseBody = "没有网络的样子\r\n\n" + responseBody;
if (responseBody.Contains("401"))
responseBody = "一卡通或者密码不太对哦\r\n\n" + responseBody;
if (responseBody.Contains("408"))
responseBody = "超时了,你的脸不行呀\r\n\n" + responseBody;
ContentDialog dialog = new ContentDialog()
{
Title = "看起来出错了呢~_~", //标题
Content = responseBody,//内容
FullSizeDesired = false, //是否全屏展示
PrimaryButtonText = "OK",
};
if (flag==1)
dialog.ShowAsync();
throw new Exception();
}
finally
{
if (Wait != null)
Wait();
}
if (Change != null)
Change(responseBody);
return responseBody;
}
public async Task<string> Post(HttpFormUrlEncodedContent postData, Action<String> TextChange, Action Wait, string url = null,int flag=1)