HLRosenberger
asked on
Using SHDocVw.InternetExplorer and WebClient.DownloadFile
I'm using SHDocVw.InternetExplorer. I have a screen scraper app. The site I am scraping requires a username/password to login. Once logged in, there is a file I want to download. WebClient.DownloadFile works great for a site/page that does not require authentication. When I try to download my file from this secure site, I get this: <script>alert('Please login first before continuing'); window.location.href = '/XXXConnect/public/Login' ;</script> .
Can I pass along the authentication credentials from SHDocVw.InternetExplorer to WebClient?
Can I pass along the authentication credentials from SHDocVw.InternetExplorer to WebClient?
ASKER
You have pointed me to something similiar in the past. I create the code from the first code exactly. This does not work. The WEB site that I'm trying to download the file from has a login page. I do not see how passing the username/password (see below) as post data accomplishes the same thing as logging in via a WEB page where a username and password is entered. In the downloadFile function, I still get the same error message as I specified in my original post.
Dim postData As String = "user_name=" & uid & "&user_password=" & pwd
Dim postData As String = "user_name=" & uid & "&user_password=" & pwd
Try this approach of logging in and see if it works
http://vbcity.com/blogs/jatkinson/archive/2009/12/12/programmatically-entering-and-data-using-the-webbrowser-control.aspx
Then try to get the authentication cookie and use it with httpwebrequest
http://stackoverflow.com/questions/650536/c-sharp-webrequest-using-webbrowser-cookie
http://vbcity.com/blogs/jatkinson/archive/2009/12/12/programmatically-entering-and-data-using-the-webbrowser-control.aspx
Then try to get the authentication cookie and use it with httpwebrequest
http://stackoverflow.com/questions/650536/c-sharp-webrequest-using-webbrowser-cookie
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The code I found at the link I provided works.
http://m4sh3d.blogspot.co.uk/2011/05/login-to-website-and-download-file.html
http://stackoverflow.com/questions/4699938/how-to-download-the-file-using-httpwebrequest-and-httpwebresponse-classcookies