我正在一个项目,该项目需要连接到运行在计算机上的运行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防火墙,但是它什么也没做。