1

I have no SSL/TLS error for running the codes below :

try
{
   System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();

    HttpResponseMessage response = await client.GetAsync("https://httpbin.org/ip");
    response.EnsureSuccessStatusCode();
    string responseBody = await response.Content.ReadAsStringAsync();
    MessageBox.Show(responseBody);
}
catch (HttpRequestException e)
{
    MessageBox.Show("\nException Caught!");
    MessageBox.Show("Message :{0} ", e.Message);
}

After that i installed HttpToSocks5Proxy from NuGet in my windows form application.
Here is the codes for test :

try
{
    ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;

    var proxy = new HttpToSocks5Proxy(host, port);
    var handler = new HttpClientHandler { Proxy = proxy };
    System.Net.Http.HttpClient httpClient = new System.Net.Http.HttpClient(handler, true);

    var result = await httpClient.SendAsync(
        new HttpRequestMessage(HttpMethod.Get, "https://httpbin.org/ip"));

    MessageBox.Show("HTTPS GET: " + await result.Content.ReadAsStringAsync());
}
catch(Exception ex)
{
    MessageBox.Show(ex.ToString());
}

Error is :

The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

The remote certificate is invalid according to the validation procedure.

And this :

The request was aborted: Could not create SSL/TLS secure channel.

As you see i've added ServicePointManager on top of those codes.
But did n't help.
I am in windows 7 os.
How can i fix that error?

SilverLight
  • 19,668
  • 65
  • 192
  • 300

0 Answers0