HttpClient Received an unexpected EOF or 0 bytes from the transport stream

请求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://www.cnblogs.com/wu_u/p/10704542.html

时间: 2024-08-29 16:39:24

HttpClient Received an unexpected EOF or 0 bytes from the transport stream的相关文章

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

/// <summary> /// 发送POST请求 /// </summary> /// <param name="json"></param> /// <returns></returns> public static string HttpPost(string requestBody) { string responseMsg = ""; try { HttpWebRequest req

bcp sqlcmd bulkinsert中unicode问题,Unexpected EOF encountered in BCP data-file

senario 进入sqlcmd用:out xxx生成数据文件,由于sqlcmd export to file 默认情况下中文乱码,故用-u(unicode)开关 @echo off & setLocal EnableDelayedExpansion :start @SET DB=AdventureWorks2012 sqlcmd -d%DB% -b -iscript.sql -v pa="out.txt" pwd="%cd%" -W -h-1 TIMEOU

SyntaxError: unexpected EOF while parsing

用Jupyter Notebook编程时,出现 SyntaxError: unexpected EOF while parsing异常, 经检查发现,是由于在编程中,不小心删掉了左括号 ) . 原文地址:https://www.cnblogs.com/xiangsui/p/9853663.html

Unexpected EOF 远程主机强迫关闭了一个现有的连接 如何处理

由于数据量的增大,调用接口的次数会增加. 当连续向目标网站发送多次request后,目标网站可能会认为是,恶意攻击. 于是会抛出requests异常. 测试代码: for i in range(200): # 连续请求200次 requests.post(p['url'], headers=p['headers'], json=p['body'], verify=False) 在python3.6中,异常为 requests.exceptions.SSLError: HTTPSConnectio

mitmproxy--Cannot establish TLS with client (sni: e.crashlytics.com): TlsException(&quot;(-1, &#39;Unexpected EOF&#39;)&quot;,) 解决办法

按崔哥(https://cuiqingcai.com/5391.html)的安装步骤一步步下来,会报这个错误: Cannot establish TLS with client (sni: e.crashlytics.com): TlsException("(-1, 'Unexpected EOF')",) 能使用mitmproxy抓到http请求了,但遇到https抓不到,而且还会阻断https请求. 解决办法: 启动mitmproxy之后,手机网打开网址:mitm.it ,选择匹配

Android4.0设置界面改动总结(二)

今年1月份的时候.有和大家分享给予Android4.0+系统设置的改动:Android4.0设置界面改动总结 时隔半年.回头看看那个时候的改动.事实上是有非常多问题的,比方说: ①.圆角Item会影响到第三方应用(由于我是公共改动的framework下的PreferenceGroupAdapter嘛). ②.设置不能横竖屏切换. 因为当时客户催的比較急,没有顾及到.只是后来.我们在做新平台的时候,是有又一次完好的,今天就和大家分享一下. 第一个问题的解决: ①.在PreferenceGroupA

Failed: error processing document #281: unexpected EOF,往MongoDB当中插入json文件时出现的错误。

往MongoDB当中插入json文件时提示的错误(我的操作系统是win10): 当时的执行命令是:mongoimport -d test -c restaurants d://primer-dataset.json 之后将 primer-dataset.json文件存入文件夹当中就可以成功插入了,执行命令为:mongoimport -d test -c restaurants d://mongoDB/primer-dataset.json 成功提示如下: 个人感觉是应该是路径选择出现的问题,我把

从传输流收到意外的 eof 或 0 个字节 win2003 解决方案。

前奏就不罗嗦了,相信看到此文的人一定已经知道该问题在何时发生. 本文是针对win2003及以下系统的,高版本系统若发生此问题,必定不是如下原因.可以尝试设置SslProtocols.Ssl3. OpenSSL 支持几个 128 位和 256 位 AES 密码套件.OpenSSL 中最开放的软件产品,在 Unix 系统上使用.例如,Sendmail. 后缀. Firefox 和 Thunderbird 中使用 OpenSSL.目前,相互提供的仅是 128 位加密套件是 RC4.没有任何的 256

hue集成hbase出现TSocket read 0 bytes

解决办法:修改hbase的配置文件 添加以下配置 https://stackoverflow.com/questions/20415493/api-error-tsocket-read-0-bytes-when-using-hue-with-hbase Add this to your hbase "core-site.conf": <property> <name>hbase.thrift.support.proxyuser</name> <