码迷,mamicode.com
首页 > 其他好文 > 详细

从传输流收到意外的 EOF 或 0 个字节

时间:2018-06-01 10:48:40      阅读:575      评论:0      收藏:0      [点我收藏+]

标签:summary   odi   cte   toc   分享   sem   设置   service   cat   


/// <summary> /// 发送POST请求 /// </summary> /// <param name="json"></param> /// <returns></returns> public static string HttpPost(string requestBody) { string responseMsg = ""; try { HttpWebRequest request; //设置https验证方式 if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase)) { ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; request = WebRequest.Create(url) as HttpWebRequest; } else { request = WebRequest.Create(url) as HttpWebRequest; } request.ContentType = "application/x-www-form-urlencoded"; request.Method = "POST"; request.Timeout = HttpTimeOut; request.ReadWriteTimeout = HttpTimeOut; byte[] data = Encoding.Default.GetBytes(requestBody); using (Stream stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); } StreamReader sr = new StreamReader(request.GetResponse().GetResponseStream()); responseMsg = sr.ReadToEnd(); } catch (Exception ex) { LogHelper.WriteLog("HttpPost", ex); } return responseMsg;

}

 

最近用let‘s encrypt制作里的https证书,给网站改为Https.更改后之前做的一些http post请求报错,提示System.Net.WebException: 基础连接已经关闭: 发送时发生错误。 ---> System.IO.IOException: 从传输流收到意外的 EOF 或 0 个字节。Received an unexpected EOF or 0 bytes from the transport stream

最终在国外某网站找到解决方法,原来是自己的接口程序.net framework版本太低。改为.net 4.5以上版本即可

 

技术分享图片

 

从传输流收到意外的 EOF 或 0 个字节

标签:summary   odi   cte   toc   分享   sem   设置   service   cat   

原文地址:https://www.cnblogs.com/xbzhu/p/9120167.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!