Accessing encrypted Site with Net.HttpWebRequest


D

dk9

I'm trying to login and comunicate with an encrypted site (SSL) using
WebRequest class, without success.



I've tried to POST the LogIn data but the the Response is always the
LogIn page, can't enter.

Dim postData As String
postData = "username=MyUserName&password=mysecretpassword1234"
Dim request As HttpWebRequest
Dim response As HttpWebResponse
request = CType(WebRequest.Create("http://server.com/names.nsf?
Login"), HttpWebRequest)
request.ContentType = "application/x-www-form-urlencoded"
request.ContentLength = postData.Length
request.Method = "POST"
request.AllowAutoRedirect = False

Dim requestStream As Stream = request.GetRequestStream()
Dim postBytes As Byte() = Encoding.ASCII.GetBytes(postData)
requestStream.Write(postBytes, 0, postBytes.Length)
requestStream.Close()
response = CType(request.GetResponse(), HttpWebResponse)

Console.WriteLine(New
StreamReader(response.GetResponseStream()).ReadToEnd())
Console.WriteLine("Headers:")
Console.WriteLine(response.Headers.ToString())




I've algo LogedIn with the WebBrowser control and then tried to copy
the Cookies to the WebRequest but without sucess:

Dim Request As System.Net.HttpWebRequest =
System.Net.WebRequest.Create(_URL)
Request.CookieContainer = New Net.CookieContainer
Request.CookieContainer.SetCookies(New Uri(_URL),
_WebBrowser.Document.Cookie)




Thanks for any help
 
Ad

Advertisements

D

dk9

I've done some research and it seems the WebRequest needs to have
certificates to access a SSL web site.

Many people have this problem but couldn't find a working, simplified
code.
Everyone has doubts and problems with their code but this is the way
to go (using certificates)

Anyone knows the best way to do this and a simple working code.


Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top