在请求中加入

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; //加上这一句

以下为c# post 请求
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public static string HttpRequest(string url)
       {
           //string returnData = null;
           string ret = string.Empty;
           try
           {
               System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
               HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(url);
               webReq.Method = "POST";
               webReq.ContentType = "application/json";
               webReq.Headers.Add("Authorization", "bearer ********");
               Stream postData = webReq.GetRequestStream();
               postData.Close();
               HttpWebResponse webResp = (HttpWebResponse)webReq.GetResponse();
               StreamReader sr = new StreamReader(webResp.GetResponseStream(), Encoding.UTF8);
               ret = sr.ReadToEnd();
                
           }
           catch (Exception ex)
           {
               //LogManager.LogInstance.WriteLog("时间:" + DateTime.Now + "/n 请求出错原因" + ex.ToString());
           }
           return ret;
       }

  

posted on   我的梦想是开个小店  阅读(1338)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示