0

I am trying to download a file that is behind a login page. I have looked into many ways to add credentials but the response is always the log in page's html. I have tried 2 passes with client.uploadValues or client.uploadstring to get a cookie and a single pass just providing credentials.

Public Sub downloadImage()
    Dim username As String = "xxxxx"
    Dim password As String = "xxxxx"
        Using client As New WebClient()
            client.Credentials = New NetworkCredential(username, password)
            client.DownloadFile("https://retailerservices.domain.com/Image/ItemHighRes/26634/1", AppDomain.CurrentDomain.BaseDirectory & "test.jpg")
        End Using
End Sub

Any recommendations?

Dan Wier
  • 334
  • 5
  • 16
  • I think the web client by default does not have a cookie container, so it will not store the cookie retrived and send it on the next request. – Mr Zach Jan 02 '21 at 23:05
  • I have adapted the answer here too to no avail. it still downloads the login page. https://stackoverflow.com/questions/11118712/webclient-accessing-page-with-credentials – Dan Wier Jan 03 '21 at 00:52
  • What kind of logon auth does the web site use? I suspect that aftter that logon page then all kinds of code behind and things like session() values etc. are set. And for security, often such web sites check the referring URL (I know I often do). that means if the current web page is NOT the result of navigation on/from my web site, I reject the request and re-direct to logon or some place else. So, the idea that you can JUST try a logon and then pull a page from such sites? NOT!!! - not even close. Try manually logging into that site, and then typing in that URL after you logon as a test. – Albert D. Kallal Jan 03 '21 at 23:33

0 Answers0