Visual Basic .NET Forums    

Go Back   Visual Basic .NET Forums > Components & Controls > Net / Sockets

VB.NET Forums Newsletter Signup:
Email address:


Net / Sockets Components for network and related use

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-14-2008, 11:28 AM
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Nov 2006
Posts: 24
Reputation: 29
leedo2k is on a distinguished programming path ahead
Exclamation Screen scraping a page behind HTTPS login page

Hi,

Can anyone help here please. I would like to authenticate myself to a website which uses HTTPS (Tomcat Server) and then after authentication, I would like to get the contents of the webpage. I bypassed the SSL certificate by using the servicepoint callback and validated the certificate.

I can do that without a problem for normal HTTP sites. But every time I try my code I get the log in page again and never get passed it. It is worth mentioning that when I try the URL I want, the server redirects my HttpWebRequest to the log in page.

Here is my code:

Code:
Imports System.IO 
Imports System.Net 
Imports System.Net.Security 
Imports System.Security.Cryptography.X509Certificates 
 
Public Class Form1 
 
    Private Function ValidateCertificate(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors As SslPolicyErrors) As Boolean 
        If certificate.Issuer.Contains("OU=CISCO") Then 
            Return True 
        Else 
            Return False 
        End If 
    End Function 
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
 
        ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateCertificate) 
 
        Dim Req As HttpWebRequest 
        'Dim SourceStream As System.IO.Stream 
        Dim Response As HttpWebResponse 
  
        '-- get file 
        Dim URL2 As String = "https://mysite.com:8443/filelist/library.htm?o_id=2" 
        Req = HttpWebRequest.Create(URL2) 
        Req.Credentials = New NetworkCredential("admin", "password") 
        Req.AllowAutoRedirect = False 
        Response = Req.GetResponse() 
        Dim sr2 As IO.StreamReader = New IO.StreamReader(Req.GetResponse.GetResponseStream) 
        '-- check responser, and make sure you are logged in 
        Dim html_data As String = sr2.ReadToEnd 
        Console.WriteLine(sr2.ReadToEnd) 
        Response.Close() 
 
    End Sub 
 
 
  
End Class
Reply With Quote
  #2 (permalink)  
Old 11-18-2008, 10:25 AM
JohnH's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2005
Location: Norway
Age: 36
Posts: 8,138
Reputation: 876
JohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond repute
Default

There could be cookies set that need to be transferred to future requests, see for example HttpWebRequest and Cookies
__________________
See this thread about how to use forum markup codes for code blocks etc (present the problem/post properly )
Some useful links: Learning videoes, WMI Code Creator, MSDN, The Code Project, WindowsClient.net, ASP.net, W3 Schools, Regular-Expressions.info, GDI+ FAQ


DR. WEIR: Download it to a non-networked, firewalled computer.
TECHNICIAN: Yes, ma'am.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -4. The time now is 5:47 AM.




Click to advertise here

Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
For advertising opportunities click here.