WebClient web page login then download
WebClient web page login then download
WebClient web page login then download
WebClient web page login then download
WebClient web page login then download
WebClient web page login then download WebClient web page login then download WebClient web page login then download WebClient web page login then download WebClient web page login then download WebClient web page login then download WebClient web page login then download WebClient web page login then download
WebClient web page login then download WebClient web page login then download
WebClient web page login then download
Go Back  Xtreme Visual Basic Talk > > > WebClient web page login then download


Reply
 
Thread Tools Display Modes
  #1  
Old 12-04-2007, 02:02 PM
dgdolins1 dgdolins1 is offline
Centurion
 
Join Date: Dec 2002
Posts: 124
Default WebClient web page login then download


Hi,

I've been trying for a while to use a method I've found on the net to login to a webpage then download zip files off the page.

Here is what I am doing:

Code:
strURL = "https://www.someurl.com/" Client = New WebClient() Dim collect As System.Collections.Specialized.NameValueCollection = New System.Collections.Specialized.NameValueCollection() collect.Add("username", "thisuser") collect.Add("password", "thispassword") Dim b As Byte() = Client.UploadValues(strURL, "POST", collect) MessageBox.Show(System.Text.Encoding.GetEncoding("iso-8859-15").GetString(b))

The problem is that this code continues to return the login page and never actually logs in. Another thing is that this page uses cookies which I understand needs to be accounted for somehow.





Here are some lines from the login page that may be of interest:

1.) <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

2.) <form name="signon" action="auth-up" method="post" enctype="application/x-www-form-urlencoded">

3.) <input type="password" name="password" size="19" tabindex="2">

4.) <input type="text" name="username" size="19" tabindex="1">

5.) <!---- Hidden field to identify forward/reverse proxy path ------>
<INPUT TYPE="hidden" NAME="proxypath" VALUE="reverse">
<INPUT type="hidden" name="context" value="default">
<INPUT type="hidden" name="url" value="https://www.thiswebsite.com/">

<input type="submit" name="button" value="Login" tabindex="3">


Any help is much appreciated.
Reply With Quote
  #2  
Old 12-17-2007, 08:37 AM
shaul_ahuvaWebClient web page login then download shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

Yes, you'll need to account for the cookies. Unfortunately, the WebClient class doesn't persist the cookies for you. However, you can inherit from WebClient and override both the GetWebRequest and GetWebResponse methods:

Your custom GetWebRequest method should add any stored cookies to the "Cookie" header before returning the WebRequest object. Your custom GetWebResponse method should retrieve any cookies from the "Set-Cookie" header and store them for the next request.

There's some basic information on HTTP cookies MSDN.
Reply With Quote
  #3  
Old 12-17-2007, 08:57 AM
dgdolins1 dgdolins1 is offline
Centurion
 
Join Date: Dec 2002
Posts: 124
Default

Thank you. I will look into this.

One other thing...cookies aside, does the code I posted appear proper? I modified and tried it on the Google search page, but it again returned the same page and didnt advance like expected.

Thanks agian.
Reply With Quote
  #4  
Old 12-18-2007, 08:37 AM
shaul_ahuvaWebClient web page login then download shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

Yes, your code looks okay. However, you need to send the values in a manner which the web server is expecting. For example, to do a search from Google's search page you would need the following code:
Code:
Dim c As New System.Net.WebClient()
Dim response() As Byte = c.DownloadData("http://www.google.com/search?q=xtremevbtalk")

MessageBox.Show(System.Text.Encoding.UTF8.GetString(response))
I used DownloadData (i.e. "GET") instead of UploadValues (i.e. "POST") because the form on Google's search page has an action of "search" (which resolves to http://www.google.com/search) and a method of "GET".

If you haven't already, you might want to download the IE developer toolbar and ieHTTPHeaders to examine the pages you are intending on targeting. Both of these tools can help you figure out how to construct your requests to the web server.
Reply With Quote
  #5  
Old 12-14-2009, 03:37 AM
computertrick computertrick is offline
Newcomer
 
Join Date: Dec 2009
Posts: 1
Smile

Quote:
Originally Posted by shaul_ahuva View Post
Yes, you'll need to account for the cookies. Unfortunately, the WebClient class doesn't persist the cookies for you. However, you can inherit from WebClient and override both the GetWebRequest and GetWebResponse methods:

Your custom GetWebRequest method should add any stored cookies to the "Cookie" header before returning the WebRequest object. Your custom GetWebResponse method should retrieve any cookies from the "Set-Cookie" header and store them for the next request.

There's some basic information on HTTP cookies MSDN.
However php which handles most login systems these days also has the option to send cookies. Now because php is protected it is impossible to right click and view the source of it which means it cant also be executed through a webclient. But if the login system uses javascript to make the cookies then this will be possible. So its very hard to find a way on how to do this. It is possible to use the web browser component and input values through their. But it is harder than normal
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
WebClient web page login then download
WebClient web page login then download
WebClient web page login then download WebClient web page login then download
WebClient web page login then download
WebClient web page login then download
WebClient web page login then download WebClient web page login then download WebClient web page login then download WebClient web page login then download WebClient web page login then download WebClient web page login then download WebClient web page login then download
WebClient web page login then download
WebClient web page login then download
 
WebClient web page login then download
WebClient web page login then download
 
-->