- 发起支付时提示:基础连接已经关闭: 发送时发生错误,是什么原因?
如题,详细代码如下: [图片] 提示:基础连接已经关闭: 发送时发生错误
2020-04-24 - 发起支付时提示:基础连接已经关闭: 发送时发生错误,是什么原因?
如题,在使用统一下单接口时,提交数据时报,基础连接已经关闭: 发送时发生错误。这种情况是什么原因造成的呢? 代码如下: System.GC.Collect();//垃圾回收 ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; var data = Encoding.GetEncoding("UTF-8").GetBytes(postStr); Stream responseStream; HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.ServicePoint.ConnectionLimit = 300; if (request == null) { throw new ApplicationException(string.Format("Invalid url string: {0}", url)); } // request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"; request.ContentType = "application/x-www-form-urlencoded"; request.Method = "POST"; request.ContentLength = data.Length; Stream requestStream = request.GetRequestStream();//报错点 requestStream.Write(data, 0, data.Length); requestStream.Close(); try { responseStream = request.GetResponse().GetResponseStream(); } catch (Exception exception) { throw exception; } string str = string.Empty; using (StreamReader reader = new StreamReader(responseStream, Encoding.GetEncoding("UTF-8"))) { str = reader.ReadToEnd(); } responseStream.Close();
2020-04-24