代码语言:javascript复制
var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip,UseProxy = false };
using (var http = new HttpClient( handler ))
{
if (headers != null)
{
foreach (KeyValuePair<string,string> header in headers)
{
http.DefaultRequestHeaders.Add( header.Key,header.Value );
}
}
if (timeout > 0)
{
http.Timeout = new TimeSpan( 0,0,timeout );
}
var response = http.GetAsync( address );
if (!response.Result.IsSuccessStatusCode)
{
return new FunctionResult<TData>() { Code = ApiStatusCode.ServerError,Message = "" };
}
var json = response.Result.Content.ReadAsStringAsync().Result;
var result = json.FromApiJson<ApiData<TData>>();
return new FunctionResult<TData> { Code = result.Result.Code,Message = result.Result.Msg,Data = result.Detail };
}
代码语言:javascript复制UseProxy = false必须加上这句,否则http请求会绕一圈