几个错误的思考,不知道是否正确。
public static async Task<HttpResponse<T>> HttpPostTaskAsync<T>(string url, object q)
{
try
{
StringContent content = new StringContent(JsonConvert.SerializeObject(q, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }));
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var ret = await _HC.PostAsync(url, content);
if (!ret.IsSuccessStatusCode)//Api相关错误,重试无效,理论上应该在开发阶段全部排除
return new HttpResponse<T>(false, ret.ReasonPhrase);
var msg = await ret.Content.ReadAsStringAsync();
return new HttpResponse<T>(true, msg);
}
catch (HttpRequestException ex)//网络错误,可以重试
{
throw;
}
catch (System.Exception ex) //其他错误,马上修改
{
throw;
}
}