Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi to all,

 

im trying to send logon information via GET to a website., but i'm having some problems. I'm using 1.1 with vs2003. This is the code i have right now

 

string sUrl;
HttpWebRequest oRequest;
CookieContainer oCookieContainer;
HttpWebResponse oResponse;
Stream oStream;
StreamReader oStreamReader;
string responseFromServer;

sUrl = "https://hotspot.ptwifi.pt/user?lg=pt&username=XXXXXXX&password=YYYYYYY";
//sUrl = "http://www.google.com";
oRequest = (HttpWebRequest)(WebRequest.Create(sUrl));
oRequest.Method = "GET";
oCookieContainer = new CookieContainer();
oRequest.CookieContainer = oCookieContainer; //this allows the cookies sent '\b' to be loaded;

oResponse = (HttpWebResponse)(oRequest.GetResponse());
oStream = oResponse.GetResponseStream();
oStreamReader = new StreamReader(oStream);
responseFromServer = oStreamReader.ReadToEnd();
Console.WriteLine (responseFromServer);//i use the result here
Console.ReadLine();

 

 

 

The error message i get is this

 

System.Net.WebException: The underlying connection was closed: Could not establish trust relationship with remote server.
  at System.Net.HttpWebRequest.CheckFinalStatus()
  at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
  at System.Net.HttpWebRequest.GetResponse()
  at ConsoleApplication1.Class1.Main(String[] args) in c:\documents and settings\rfazendeiro\my documents\visual studio projects\consoleapplication1\class1.cs:line 35

 

 

does anyone have any ideia how to resolve this?

thx in advance

  • 3 months later...
Posted

You are most likely experiencing the same problem as I described here:

 

http://www.xtremedotnettalk.com/showthread.php?t=96720&highlight=Certificate

 

You have problably encountered this error at some point while browsing the web (see attached image). When it happens in a web browser your browser will notify you with a popup and ask you what to do. When communicating with SSL programmatically, .NET will blow up and throw the Exception you received unless you specify how you want to handle the situation ahead of time.

 

You need to create a class that implements the ICertificatePolicy interface (creating a policy regarding how you want to handle trust related issues) and then bind it to your request.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...