在请求中加入
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; } |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步