HttpPost 报错 System.Net.WebException: 基础连接 : 连接被意外关闭
调用失败:System.Net.WebException: 基础连接已经关闭: 连接被意外关闭。
在 System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
在 System.Net.HttpWebRequest.GetRequestStream()
在 WCS.Common.Util.CSHttpHelp.HttpPost(String postUrl, String postBody)
在 Client.Call(String action, String floor, Int32 type)
postman可以正常访问,各种方法都尝试了,都不行
代码如下:
public static string HttpPost(string postUrl, string postBody)
{
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(postUrl);
request.ContentType = "application/json";
request.Method = "POST";
request.Timeout = 300000;
request.KeepAlive = false;
request.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(postBody);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
using (System.IO.StreamReader myreader = new System.IO.StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
return myreader.ReadToEnd();
}
}