RestSharp 封状实例

2019/05/15 10:33
阅读数 141


1
public class Rest<T> 2 { 3 private static Logger logger = LogManager.GetCurrentClassLogger(); 4 private IRestClient client; 5 string proxyIp = AppConfig.proxyIp; 6 int proxyPort = AppConfig.proxyPort; 7 public Rest(string url) 8 { 9 10 client = new RestClient(url);
// 代理
11 client.Proxy = new WebProxy(proxyIp, proxyPort); 12 } 13 public async Task<T> RestExecute(RestRequest request) 14 { 15 try 16 {
  //HTTPS
17 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;20 //request.AddHeader("Content-Type", "application/json"); 21 IRestResponse<T> response = await client.Execute<T>(request); 22 logger.Debug("====== Rest response:" + JsonConvert.SerializeObject(response)); 23 return response.Data; 24 } 25 catch (Exception ex) 26 { 27 logger.Error("====== Rest error:" + ex.Message); 28 } 29 return default(T); 30 } 31 }

 

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部