在请求中加入

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

以下为c# post 请求
 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 2021-06-08 16:54  我的梦想是开个小店  阅读(1430)  评论(0)    收藏  举报