HttpClient Received an unexpected EOF or 0 bytes from the transport stream
2019-04-14 11:57
876 查看
请求https链接时报错,奇怪的是pc1正常,pc2异常
Unhandled Exception: System.AggregateException: One or more errors occurred. ( Received an unexpected EOF or 0 bytes from the transport stream.) ---> System.IO.IOException: Received an unexpected EOF or 0 bytes from the transport stream.
at System.Net.Security.SslStreamInternal.<FillBufferAsync>g__InternalFillBufferAsync|38_0[TReadAdapter](TReadAdapter adap, ValueTask`1 task, Int32 min, Int32 initial)
原因:大概是请求时默认了一个过时了的ssl协议
解决:指定tls 1.0或其他有效协议,参考https://stackoverflow.com/questions/25414907/authenticateasclient-system-io-ioexception-received-an-unexpected-eof-or-0-byt
class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); var html = GetClientStringAsync("https://**********").Result; Console.Write(html); Console.ReadLine(); } public static async Task<string> GetClientStringAsync(string url, string encoding = "utf-8") { var result = string.Empty; var httpClientHandler = new HttpClientHandler { SslProtocols = System.Security.Authentication.SslProtocols.Tls }; HttpClient client = new HttpClient(httpClientHandler); client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"); var bytes = await client.GetByteArrayAsync(url); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); result = Encoding.GetEncoding(encoding).GetString(bytes); return result; } }
相关文章推荐
- https使用HttpWebRequest出现错误:System.IO.IOException: Received an unexpected EOF or 0 bytes from the transport stream.的解决方法
- An unexpected error prevented the server from fulfilling your request. (HTTP 500)
- The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the serv
- keystone创建服务实体HTTP500,An unexpected error prevented the server from fulfilling your request. HTTP500
- 【httpclient】Attempted read from closed stream
- Dynamics CRM 本地插件注册器连CRMAn unsecured or incorrectly secured fault was received from the other party
- Error message when you try to install a SQL Server 2005 service pack or a SQL Server 2005 hotfix package: "Error 29528. The setup has encountered an unexpected error while Setting Internal Properties"
- HTTP Status 500 - description The server encountered an internal error () that prevented it from fulfilling this request.错误解决办法
- 解决:The proxy server received an invalid response from an upstream server
- HttpWebRequest以UTF-8编码写入内容时发生“Bytes to be written to the stream exceed the Content-Length bytes size specified.”错误
- The proxy server received an invalid response from an upstream server.(错误原因)
- (转)HttpWebRequest以UTF-8编码写入内容时发生“Bytes to be written to the stream exceed the Content-Length bytes size specified.”错误
- Unexpected EOF from the server.
- keystone -- An unexpected error prevented the server from fulfilling your request. 错误
- 【Android Studio错误】 If you are behind an HTTP proxy, please configure the proxy settings either in IDE or Gradle.
- If you are behind an HTTP proxy, please configure the proxy settings either in IDE or Gradle.
- Send an image from the iPhone using ASIHTTP and UIImagePicker
- The server encountered an unexpected condition that prevented it from fulfilling the request.
- If you are behind an HTTP proxy, please configure the proxy settings either in IDE or Gradle.(AS报错)
- 502 Proxy Error The proxy server received an invalid response from an upstream server