Why do I get errors when trying to connect to localhost?

0

I am working on a project that needs to connect to a node.js server running express.js that is running on my computer. I run the following code:

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();

and get the following error:

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.

The code is intended to connect to the server, read a test file that is running on it and return the contents of the file.

I have also tried turning off windows firewall but it doesn't do anything.

c#
httpwebrequest
asked on Stack Overflow Dec 26, 2019 by Kayos

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0