954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Net.Downloaddata problems

Ok i have this code to download some data

Private Sub Getfiles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Getfiles.Click
        Webbrowser.Navigate(New System.Uri("http://mail.google.com/mail/feed/atom"))
        Dim Net As New System.Net.WebClient
        AtomFeed = System.Text.Encoding.ASCII.GetString(Net.DownloadData("http://mail.google.com/mail/feed/atom"))
        Atomfeedtext.Text = AtomFeed
    End Sub


Every Time i run it i get a 401 Unauthorised Error

I believe this because the web browser has logged in but the net has not, so can i make the net interact with the web browser to give me the authorisation or should i make it log on to both

Heres my Web Browser login script

Dim Document As Object
        If Login.Text = "Login" Then
            On Error Resume Next
            Document = Webbrowser.Document.DomDocument

            Document.Forms(0).email.Value = User.Text
            Document.Forms(0).passwd.Value = Pass.Text
            Document.Forms(0).submit()

            Login.Text = "Logout"
            Getfiles.Enabled = True
        Else
            Webbrowser.Navigate(New System.Uri("http://mail.google.com/mail/?logout&hl=en"))
            Login.Text = "Login"
            Getfiles.Enabled = False
        End If


oh and heres the atomfeed Dim if you want it

Dim AtomFeed As Object


Thanks for your help

Sacky
Newbie Poster
11 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
 

I was thinking of using some sort of HTTP screen scraping for this instead, does anyone know any tutorials to start me off?

Sacky
Newbie Poster
11 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
 

This will allow you to download http://mail.google.com/mail/feed/atom and get its HTML

Dim wc As New System.Net.WebClient() 'New web client
        wc.Credentials = New System.Net.NetworkCredential("gmail user name here", "gmail password here") 'Enter login info
        Dim html As String = System.Text.Encoding.ASCII.GetString(wc.DownloadData("http://mail.google.com/mail/feed/atom")) 'Download HTML
        RichTextBox1.Text = html 'Set the HTML into the rich text box
tayspen
<Insert title here>
Team Colleague
1,622 posts since Jul 2005
Reputation Points: 84
Solved Threads: 99
 

That worked thanks :)
But now ive got another problem

Heres the code:

Private Sub WebBrowser_DocumentCompleted(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs, ByVal pDisp As Object) Handles Webbrowser.DocumentCompleted
        Dim URL As String = eventArgs.Url.ToString()
        Dim i As Object
        If Webbrowser.Url.ToString() = "http://mail.google.com/mail/feed/atom" Then
            On Error Resume Next
            If (pDisp Is Webbrowser.Object) Then
                html.Text = ""
                FilesList.Items.Clear()
                For i = 0 To 520
                    If (VB.Left(Webbrowser.Document.DomDocument.All(i).innerHTML, 7)) = "GMAILFS" Then
                        html.Text = html.Text & Webbrowser.Document.DomDocument.All(i).innerHTML & vbNewLine
                        html.Text = html.Text & Webbrowser.Document.DomDocument.All(i + 21).innerHTML & vbNewLine & vbNewLine
                        FilesList.Items.Add(Mid(Webbrowser.Document.DomDocument.All(i + 21).innerHTML, 68 + Len(Atomfeedtext.Text), 16))
                    End If
                Next
            End If
        End If
    End Sub
End Class


My two errors are:

Webbrowser.DocumentCompleted
Method 'Private Sub WebBrowser_DocumentCompleted(eventSender As Object, eventArgs As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs, pDisp As Object)' cannot handle Event 'Public Event DocumentCompleted(sender As Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)' because they do not have the same signature

and

If (pDisp Is Webbrowser.Object) Then
'Object' is not a member of 'System.Windows.Forms.WebBrowser'.

Are there any suggestions?

Sacky
Newbie Poster
11 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You