c# - 为什么在尝试连接到 localhost 时会出现错误?
问题描述
我正在开发一个需要连接到运行 express.js 的 node.js 服务器的项目,该服务器正在我的计算机上运行。我运行以下代码:
HttpWebRequest myRequest;
WebResponse myResponse;
StreamReader sr;
myRequest = (HttpWebRequest)WebRequest.Create("https://localhost:1337/Test.txt");
myRequest.Method = "GET";
myResponse = myRequest.GetResponse();
sr = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
sr.Close();
myResponse.Close();
并得到以下错误:
System.Windows.Markup.XamlParseException
HResult=0x80131501
Message=The invocation of the constructor on type 'MyNamespace.MyClass' that matches the specified binding constraints threw an exception.
Source=PresentationFramework
StackTrace:
at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
This exception was originally thrown at this call stack:
System.Net.Security.SslStream.StartReadFrame(byte[], int, System.Net.AsyncProtocolRequest)
System.Net.Security.SslStream.PartialFrameCallback(System.Net.AsyncProtocolRequest)
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Net.Security.SslStream.ThrowIfExceptional()
System.Net.Security.SslStream.InternalEndProcessAuthentication(System.Net.LazyAsyncResult)
System.Net.Security.SslStream.EndProcessAuthentication(System.IAsyncResult)
System.Net.Security.SslStream.EndAuthenticateAsClient(System.IAsyncResult)
System.Net.Security.SslStream.AuthenticateAsClientAsync.AnonymousMethod__65_1(System.IAsyncResult)
System.Threading.Tasks.TaskFactory<TResult>.FromAsyncCoreLogic(System.IAsyncResult, System.Func<System.IAsyncResult, TResult>, System.Action<System.IAsyncResult>, System.Threading.Tasks.Task<TResult>, bool)
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
...
[Call Stack Truncated]
Inner Exception 1:
WebException: The SSL connection could not be established, see inner exception. The handshake failed due to an unexpected packet format.
Inner Exception 2:
HttpRequestException: The SSL connection could not be established, see inner exception.
Inner Exception 3:
IOException: The handshake failed due to an unexpected packet format.
该代码旨在连接到服务器,读取在其上运行的测试文件并返回文件的内容。
我也试过关闭windows防火墙,但它什么也没做。
解决方案
推荐阅读
- sql - LEFT JOIN CASE QUERY 上的 SUM() 输出不正确
- mysql - 我可以在一张表中有几个相似的外键吗?
- apache-kafka - 如何将“重新分区/更改日志主题”绑定到 Kafka Streams 应用程序中已存在的主题
- react-native - axios 调用失败时可能出现未处理的 Promise Rejection 警告
- java - 从 Java 中的优先级队列中删除一系列元素
- sql-server - IF EXISTS 创建新表和/或列的逻辑
- dart - 为什么我无法定位 SpinKitFadingCircle?
- automation - Telegram bot:如何在私人聊天中为收件人添加按钮
- rust - 对于 `std::error::Error` 和 `#from` 指令,使用 `thiserror::Error` 自动实现 `From` 失败
- apache-spark - pyspark - 将列字符串转换为标题和值