HTTP GET over SSL, C#. Unable to connect to the remote server

  • Thread starter Thread starter bonnieliyl
  • Start date Start date
B

bonnieliyl

This is driving me nuts!! Anyone, please help...

I would like to send an HTTP GET request to a server over SSL and I am
using System.Net.HttpWebRequest to do so. I have the valid certificate
installed to the Current User. That's for sure because I am able to
access the same resource using IE. But my code isn't working. Everytime
it receives a WebException, whose status is ConnectFailure, which means
"The remote service point could not be contacted at the transport
level.", also whose message is as below,

The underlying connection was closed: Unable to connect to the remote
server.
Stack: at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult
asyncResult)
at System.Net.HttpWebRequest.GetResponse()

I've tried to access both a server locating outside and inside of our
Intranet. The same thing happens that the request was sent to our proxy
server, no matter if I enable or disable the proxy settings at IE. It
should be sent straight to the right destination!

I was using Ethereal to capture the packets. While in the case of using
IE when it's working properly, no matter how the proxy is set, if the
url contains a DNS name, it at first looks up to the DNS server,
returns the proper IP address, and then the packets are sent between my
own computer and the server directly, over SSLv3. But with my code, it
never goes that far. It always connects to the proxy and ofcourse the
program got bounced with error message!

Really don't understand
1) why the proxy is always playing there even after I've disabled it?
or
2) it's said that HttpWebRequest is using the same network settings
with IE but seems it isn't?
3) with unmanaged C++, it's quite simple by just setting one flag when
establing the HTTPS and before that loading the right certificate to
the system store. How is C# different from this scenario? Even if
there's a difference, .NET is meant to be simpler but not complexer!

Thanks for any comments. Am really desperate here....
 
This is driving me nuts!! Anyone, please help...

I would like to send an HTTP GET request to a server over SSL and I am
using System.Net.HttpWebRequest to do so. I have the valid certificate
installed to the Current User. That's for sure because I am able to
access the same resource using IE. But my code isn't working. Everytime
it receives a WebException, whose status is ConnectFailure, which means
"The remote service point could not be contacted at the transport
level.", also whose message is as below,

The underlying connection was closed: Unable to connect to the remote
server.
Stack: at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult
asyncResult)
at System.Net.HttpWebRequest.GetResponse()

I've tried to access both a server locating outside and inside of our
Intranet. The same thing happens that the request was sent to our proxy
server, no matter if I enable or disable the proxy settings at IE. It
should be sent straight to the right destination!

I was using Ethereal to capture the packets. While in the case of using
IE when it's working properly, no matter how the proxy is set, if the
url contains a DNS name, it at first looks up to the DNS server,
returns the proper IP address, and then the packets are sent between my
own computer and the server directly, over SSLv3. But with my code, it
never goes that far. It always connects to the proxy and ofcourse the
program got bounced with error message!

Really don't understand
1) why the proxy is always playing there even after I've disabled it?
or
2) it's said that HttpWebRequest is using the same network settings
with IE but seems it isn't?
3) with unmanaged C++, it's quite simple by just setting one flag when
establing the HTTPS and before that loading the right certificate to
the system store. How is C# different from this scenario? Even if
there's a difference, .NET is meant to be simpler but not complexer!

Thanks for any comments. Am really desperate here....

Hi, the problem is that your http connection is rejecting the ssl cert.
You will need to ServicePointManager instead of HttpRequest and
override CheckValidationResult to always return true. There are a few
KB's on this but i can't find the links.
 
Hey Rob,

Thanks a lot for the reply.

My problem has been solved. I tried first at home computer without any
proxy and firewall settings that have been configured for my office PC,
it worked. Then I was sure the problem must lie on the network
settings, not my code. Got a tip from others on how to set an empty
proxy programmatically, not the way I first tried:

req.Proxy = new WebProxy(); // wrong!!

but like this:

req.Proxy = GlobalProxySelection.GetEmptyWebProxy(); // works!!

Then the magic started. :-) Couldn't believe it's such a small line
that makes all the difference.

Merry Christmas and Happy New Year!!

Best regards, Bonnie
 
Back
Top