using System; using System.Collections.Generic; using System.Configuration; using System.IO; using System.Net; using System.Net.Http; using System.Text; namespace Common { public class ApiHelper { #region 配置 private static string _url = null; private static HttpHelper httpHelper = new HttpHelper(); #endregion /// /// get请求 /// /// /// public static string Get(string url, WebHeaderCollection header) { return httpHelper.GetData(new HttpItem { Url = url, Method = "get", Header = header }).Html; } /// /// get请求 /// /// /// public static string Get(string url) { return httpHelper.GetData(new HttpItem { Url = url, Method = "get" }).Html; } /// /// post请求 /// /// /// /// public static string Post(string url, object jsonObj) { return httpHelper.GetData(new HttpItem { Url = url, Method = "post", ContentType = "application/json", Timeout = 90 * 1000, ReadWriteTimeout = 90 * 1000, Encoding = Encoding.UTF8, Postdata = jsonObj.TryToJson(), }).Html.TryJsonToT().body.ToString(); } private static void AddHeader(HttpClient http, Dictionary header) { if (header == null) return; foreach (var item in header) { http.DefaultRequestHeaders.Add(item.Key, item.Value);//添加headers } } } public class BaseJsonResult { /// /// 状态编码 /// public int code { get; set; } /// /// 数据 /// public object body { get; set; } /// /// 返回信息 /// public string msg { get; set; } /// /// 发送时间 /// public DateTime stime { get; set; } } }