0

I need to download files from a website but I need to login first. How can I do it using vb.Net and WebClient? I tried using cookies but it looks my code is ignoring them.

I am using the following code that works to download any other file that does not require previous login/authentication.

Dim wc as WebClient
wc = New WebClient()

Dim fldBrowser As New FolderBrowserDialog()
Dim path = ""
If fldBrowser.ShowDialog() = DialogResult.OK Then path = fldBrowser.SelectedPath.ToString()

Dim token As New Cookie("csrftoken", "Zfx...cd", "/", "www...com.br")
Dim sessionId As New Cookie("sessionid", "6S...6w", "/", "www....com.br")

Dim cookieContainer As New CookieContainer
cookieContainer.Add(sessionId)
cookieContainer.Add(token)

url = "url"
wc.DownloadFileAsync(New Uri(url), path + "\" + "Teste.pdf")
Marcelo Gazzola
  • 907
  • 12
  • 28

0 Answers0