1 首先网上百度 HttpHelper 这个类,加入项目
2 如果使用的是https协议需要加入以下代码
ServicePointManager.ServerCertificateValidationCallback += (s, cert, chain, sslPolicyErrors) => true;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
3 正文代码
string tokens = "XXXX";
string tempurl = "https://XXXXXXX";
HttpHelper http = new HttpHelper();
var data = new { t = XXXX, orgId = XXXX, pageNo = 1, pageSize = 10 };
string json = JsonConvert.SerializeObject(data);
HttpItem item = new HttpItem()
{
URL = tempurl,
Method = "post",
Accept = "application/json, text/plain, */*",
Postdata = json,
ContentType = "application/json;charset=UTF-8"
};
item.Header.Add("Accept-Encoding", " gzip");
item.Header.Add("app-version:2.0.2");
item.Header.Add("terminal-type: PC̵M5Z̵AndroidMobile̵iOS");
item.Header.Add("product: kqhl");
item.Header.Add("platform: mobile");
item.Header.Add("token: " + tokens.Trim());
HttpResult result = http.GetHtml(item);
string html = result.Html;