Showing posts with label https. Show all posts
Showing posts with label https. Show all posts

Monday, November 24, 2014

Capturing traffic from .Net app to https://localhost using Fiddler

Recently I was trying to capture traffic from my .Net help to a site hosted in IIS Express at  https://localhost:port
The issue was that fiddler wasn't capturing these requests. I found various alternatives like using IP address or machine name but that would results in certificate errors due to host name mismatch.

Finally found the option of using https://localhost.fiddler:port instead of https://localhost:port which would then capture the traffic in Fiddler.

Friday, January 6, 2012

Could not establish trust relationship for the SSL/TLS secure channel

This is a common problem in the testing world where you deploy a service on a HTTPS endpoint by using a self-signed certificate.
When you try to send a request to this service using HTTPWebRequest/WebClient, you see the error:
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
The solution to this problem is to ignore the trust by using the following code:

using System.Net;
using System.Net.Security;

           
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.mysite.com");

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Stream stream = response.GetResponseStream();

StreamReader sr = new StreamReader(stream);

string resp = sr.ReadToEnd();