在请求中加入
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;
}
浙公网安备 33010602011771号