HTTPS and WebRequest

  • Thread starter Thread starter Tony Guidici
  • Start date Start date
T

Tony Guidici

I have been attempting to send an XML post to a ASPX page I created as a
listener. On our Windows Server 2003 Web Edition server, I installed a test
certificate from Thawte and can hit the page just fine from the browser.
However, when I attempt to use the WebRequest object to post to the page, I
get the folowing error:

"The underlying connection was closed: Could not establish trust
relationship with remote server."

I used the following code:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(client.OutboundURL);

req.Method = "POST";

req.ContentType = "text/xml";

req.PreAuthenticate = true;

req.Credentials = new NetworkCredential(client.WebSendID,
client.WebSendPwd);

Stream xmlSend;

try

{

xmlSend = req.GetRequestStream();

}

catch(Exception ex)

{

Debug.WriteLine("Error getting stream to outbound resource.");

throw ex;

}


The code works fine if I use HTTP instead of HTTPS. I have searched Google,
MSDN, and any other source I can find, with some answers that haven;t worked
so far.

Can anyone help me?

Thanks,

Tony Guidici

President, Sr. Consultant
Vero Solutions, Inc.
 
You would have to do this.

1. export the certificate to x.509 format and place it on the webserver.
2. Add the certificate to the httprequest.certificate collection.
3. Install the certificate in the ie of the webserver.

Check with steps 1 and 2 only first. If not working do step 3 also.
 
Rajesh.V said:
You would have to do this.

1. export the certificate to x.509 format and place it on the
webserver. 2. Add the certificate to the httprequest.certificate
collection. 3. Install the certificate in the ie of the webserver.

Depending on the certificate (and especially with this one), this is not
sufficient. He also needs to provide an appropriate ICertificatePolicy
that does not reject the server certificate, since the FCL's default
implementation will do that.

Cheers,
 
Back
Top