user198989
user198989

Reputation: 4663

VB.NET - Navigate webpage with specified user-agent?

I'm trying to change current user gaent to different user-agent. This one naviagtes the webpage, however, doesnt change the user-agent.

    Dim webBrowser1 As Object
    webBrowser1 = CreateObject("InternetExplorer.Application")
    webBrowser1.Navigate("http://www.example.org", Nothing, Nothing, "User-Agent: blabla")

What is the correct way to do that ?

Upvotes: 1

Views: 1614

Answers (1)

Alex
Alex

Reputation: 636

You create a System.Net.Webclient instead and give it the wanted headers.

Imports System.Net

Module Module1
    Sub Main()


        ' Resource acquisition statement.
        Using client As New WebClient
            ' Set one of the headers.
            client.Headers("User-Agent") = "Mozilla/4.0"

            ' Download data as byte array.
            Dim arr() As Byte = client.DownloadData("http://www.dotnetperls.com/")

            ' Display result.
            Console.WriteLine(arr.Length)
        End Using
    End Sub
End Module

Source: http://www.dotnetperls.com/webclient-vbnet

Upvotes: 2

Related Questions