Click here to Skip to main content
15,913,685 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I logon to mturk.com from Google Chrome.

Then I try to download from that site:
VB
Dim HTML As String
                Dim texttosend As String = "https://www.mturk.com/mturk/viewhits"
                Dim res As Byte() = web.DownloadData(texttosend)
                HTML = System.Text.Encoding.ASCII.GetString(res)


... but the returned html is as if I hadn't logged on. Why can't I impersonate myself?

[EDIT]Answer 1 included[/EDIT]
Thanks Dave...hmmm... for some reason I didn't realize I needed that.
So I tried adding:
VB
Dim texttosend As String = "https://www.mturk.com/mturk/viewhits"
Dim web As New System.Net.WebClient
web.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim res As Byte() = web.DownloadData(texttosend)
dim HTML as string = System.Text.Encoding.ASCII.GetString(res)

... but that doesn't help. The HTML text is still what I would get without the credentials.

I'm not using process.start here. Do I need to?

Thanks in advance
Posted
Updated 23-May-13 18:42pm
v2
Comments
[no name] 23-May-13 19:50pm    
Did you set the credentials? http://msdn.microsoft.com/en-us/library/system.net.webclient.credentials.aspx
Dave Kreskowiak 23-May-13 21:38pm    
Sooooo where's the code where you provided the credentials to the WebRequest?

and I don't see any mention of a Process.Start in this code snippet...
Dave Kreskowiak 24-May-13 11:33am    
I see what you're doing. This is not going to work. You cannot use the NetCredentials with the WebClient class to login to a website that requires you to type in a username and password. If the site used an authentication method, wuch as Windows Authentication, then the credentials would work.

You have to download the login page, fill in the username and password fields, then POST the page back. There's a short example on how to do that at http://technet.rapaport.com/Info/Prices/SampleCode/Get_File_With_Post_Request_Using_WebClient.aspx

1 solution

Yes, sorry, the title of my post did not match the question.

Basically, I'm trying to reach a website that needs credentials. Those credentials are entered as still a different website. But I am already logged into that site on my machine. Can I not tell vb.net that that is the case and that it should use the existing session in a web download?

Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900