C# net request payload形式发送post请求 改进版,加了https协议,还有一些类

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;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值