473,488 Members | 2,516 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Logon internetsite and download file

Hi,,

Can anyone tell me how to log on to a internet website with username and
password, navigate to other subpages on that site, and then start downloading
a textfile to disk??

Thanks
Nov 21 '05 #1
10 1405
Here's a snip from a web spider I wrote last year:
<snip>
Private Function getHtml(ByVal i As Integer) As String

Dim url As String = "http://www.wtng.info/wtng-" & Chr(i) & Chr(i) &
".html"
Dim reader As StreamReader
Dim html As String

Try
reader = New StreamReader( _
CType( _
CType( _
WebRequest.Create(url), _
HttpWebRequest).GetResponse(), _
HttpWebResponse).GetResponseStream())

html = reader.ReadToEnd()
reader.Close()

Catch ex As Exception
Try: reader.Close(): Catch exc As Exception: End Try
html = ""
Console.WriteLine("Could not connect to " & url)
End Try

Return html.Trim()

End Function
</snip>

--
Peace & happy computing,

Mike Labosh, MCSD
"Musha ring dum a doo dum a da!" -- James Hetfield
"Henrik" <He****@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...
Hi,,

Can anyone tell me how to log on to a internet website with username and
password, navigate to other subpages on that site, and then start
downloading
a textfile to disk??

Thanks

Nov 21 '05 #2
Here's a snip from a web spider I wrote last year:
<snip>
Private Function getHtml(ByVal i As Integer) As String

Dim url As String = "http://www.wtng.info/wtng-" & Chr(i) & Chr(i) &
".html"
Dim reader As StreamReader
Dim html As String

Try
reader = New StreamReader( _
CType( _
CType( _
WebRequest.Create(url), _
HttpWebRequest).GetResponse(), _
HttpWebResponse).GetResponseStream())

html = reader.ReadToEnd()
reader.Close()

Catch ex As Exception
Try: reader.Close(): Catch exc As Exception: End Try
html = ""
Console.WriteLine("Could not connect to " & url)
End Try

Return html.Trim()

End Function
</snip>

--
Peace & happy computing,

Mike Labosh, MCSD
"Musha ring dum a doo dum a da!" -- James Hetfield
"Henrik" <He****@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...
Hi,,

Can anyone tell me how to log on to a internet website with username and
password, navigate to other subpages on that site, and then start
downloading
a textfile to disk??

Thanks

Nov 21 '05 #3
"Henrik" <He****@discussions.microsoft.com> schrieb:
Can anyone tell me how to log on to a internet website with username and
password, navigate to other subpages on that site, and then start
downloading
a textfile to disk??


\\\
Dim w As New WebClient()
w.Credentials = New NetworkCredential("username", "password")
w.DownloadFile(...)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4
"Henrik" <He****@discussions.microsoft.com> schrieb:
Can anyone tell me how to log on to a internet website with username and
password, navigate to other subpages on that site, and then start
downloading
a textfile to disk??


\\\
Dim w As New WebClient()
w.Credentials = New NetworkCredential("username", "password")
w.DownloadFile(...)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #5
Hi Mike,,

Thanks for you reply,, But it's not quite that im looking for?

I want to connect to a site, where in need to type in my username and
password on a form and submit this form. After valid check i get a new page,
where i can download a ".txt"-file. And it's this file im interesed in..

I've got the download procedure to work just fine by using a
"WebClient1"-component.. But my main problem is the logon-procedure to the
site. I've tried this:

Dim w As New WebClient
w.Credentials = New NetworkCredential("username", "password")
w.DownloadFile("https://Reports/xx/xxx.TXT", "c:\xxx.TXT")

It's saves a file,, but its the logonpage??

"Mike Labosh" wrote:
Here's a snip from a web spider I wrote last year:
<snip>
Private Function getHtml(ByVal i As Integer) As String

Dim url As String = "http://www.wtng.info/wtng-" & Chr(i) & Chr(i) &
".html"
Dim reader As StreamReader
Dim html As String

Try
reader = New StreamReader( _
CType( _
CType( _
WebRequest.Create(url), _
HttpWebRequest).GetResponse(), _
HttpWebResponse).GetResponseStream())

html = reader.ReadToEnd()
reader.Close()

Catch ex As Exception
Try: reader.Close(): Catch exc As Exception: End Try
html = ""
Console.WriteLine("Could not connect to " & url)
End Try

Return html.Trim()

End Function
</snip>

--
Peace & happy computing,

Mike Labosh, MCSD
"Musha ring dum a doo dum a da!" -- James Hetfield
"Henrik" <He****@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...
Hi,,

Can anyone tell me how to log on to a internet website with username and
password, navigate to other subpages on that site, and then start
downloading
a textfile to disk??

Thanks


Nov 21 '05 #6
Hi Mike,,

Thanks for you reply,, But it's not quite that im looking for?

I want to connect to a site, where in need to type in my username and
password on a form and submit this form. After valid check i get a new page,
where i can download a ".txt"-file. And it's this file im interesed in..

I've got the download procedure to work just fine by using a
"WebClient1"-component.. But my main problem is the logon-procedure to the
site. I've tried this:

Dim w As New WebClient
w.Credentials = New NetworkCredential("username", "password")
w.DownloadFile("https://Reports/xx/xxx.TXT", "c:\xxx.TXT")

It's saves a file,, but its the logonpage??

"Mike Labosh" wrote:
Here's a snip from a web spider I wrote last year:
<snip>
Private Function getHtml(ByVal i As Integer) As String

Dim url As String = "http://www.wtng.info/wtng-" & Chr(i) & Chr(i) &
".html"
Dim reader As StreamReader
Dim html As String

Try
reader = New StreamReader( _
CType( _
CType( _
WebRequest.Create(url), _
HttpWebRequest).GetResponse(), _
HttpWebResponse).GetResponseStream())

html = reader.ReadToEnd()
reader.Close()

Catch ex As Exception
Try: reader.Close(): Catch exc As Exception: End Try
html = ""
Console.WriteLine("Could not connect to " & url)
End Try

Return html.Trim()

End Function
</snip>

--
Peace & happy computing,

Mike Labosh, MCSD
"Musha ring dum a doo dum a da!" -- James Hetfield
"Henrik" <He****@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...
Hi,,

Can anyone tell me how to log on to a internet website with username and
password, navigate to other subpages on that site, and then start
downloading
a textfile to disk??

Thanks


Nov 21 '05 #7
Hi Herfried,,

Thanks for replying :o)

I have tried that?,, it only takes me to the loginform with the username,
password and submitbutton :o(.. And i have even tried to write in the whole
url to the file, but still no luck??

Do i really have to "fill" in username and password and make the
submit-action programly instead?? and the call the url with the file to
download afterwards?

Thanks

"Herfried K. Wagner [MVP]" wrote:
"Henrik" <He****@discussions.microsoft.com> schrieb:
Can anyone tell me how to log on to a internet website with username and
password, navigate to other subpages on that site, and then start
downloading
a textfile to disk??


\\\
Dim w As New WebClient()
w.Credentials = New NetworkCredential("username", "password")
w.DownloadFile(...)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #8
Hi Herfried,,

Thanks for replying :o)

I have tried that?,, it only takes me to the loginform with the username,
password and submitbutton :o(.. And i have even tried to write in the whole
url to the file, but still no luck??

Do i really have to "fill" in username and password and make the
submit-action programly instead?? and the call the url with the file to
download afterwards?

Thanks

"Herfried K. Wagner [MVP]" wrote:
"Henrik" <He****@discussions.microsoft.com> schrieb:
Can anyone tell me how to log on to a internet website with username and
password, navigate to other subpages on that site, and then start
downloading
a textfile to disk??


\\\
Dim w As New WebClient()
w.Credentials = New NetworkCredential("username", "password")
w.DownloadFile(...)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #9
I have the exact same problem.
I need to download the csv file from Google AdSense.
Google requires the name and password to be send using "POST" method.

This code (below) will only download the html content of the page, but
if url points to file it doesn't do anything. Can someone amend this
code to work for files as well?

Public Function GetPageHTML(ByVal URL As String) As String
Dim myWebClient As New WebClient
Dim myNameValueCollection As New NameValueCollection
myNameValueCollection.Add("username", "joedoe")
myNameValueCollection.Add("password", "123456")
Dim responseArray As Byte() = myWebClient.UploadValues(URL,
"POST", myNameValueCollection)
GetPageHTML = Encoding.UTF8.GetString(responseArray)
End Function

Nov 21 '05 #10
Fixed my problem by doing this:

Dim Request As HttpWebRequest
Dim Response As HttpWebResponse
Dim URL As String = "https://login.form"
Dim Params As String = "action=login&username=" & User & "&password=" & Pwd
& "&submit=login"
Dim CC As New CookieContainer
Dim myWriter As StreamWriter
Dim sr As StreamReader

Request = WebRequest.Create(url)
Request.Timeout = 120 * 1000
Request.CookieContainer = CC
Request.Method = "POST"
Request.ContentLength = params.Length
Request.ContentType = "application/x-www-form-urlencoded"
Request.KeepAlive = True
myWriter = New StreamWriter(Request.GetRequestStream())
myWriter.Write(params)

myWriter.Close()
Response = Request.GetResponse()
Response.Cookies = Request.CookieContainer.GetCookies(Request.Request Uri)

For i = 0 To Response.Cookies.Count - 1
CC.Add(Response.Cookies(i))
Next

sr = New StreamReader(Response.GetResponseStream(), Encoding.GetEncoding(850))
ResultHTML = sr.ReadToEnd()
-----------------------------------------------------------------------------

Then i could create a new request and navigate to the page with my file..

Thanks for your help


"MARTIN LANNY" wrote:
I have the exact same problem.
I need to download the csv file from Google AdSense.
Google requires the name and password to be send using "POST" method.

This code (below) will only download the html content of the page, but
if url points to file it doesn't do anything. Can someone amend this
code to work for files as well?

Public Function GetPageHTML(ByVal URL As String) As String
Dim myWebClient As New WebClient
Dim myNameValueCollection As New NameValueCollection
myNameValueCollection.Add("username", "joedoe")
myNameValueCollection.Add("password", "123456")
Dim responseArray As Byte() = myWebClient.UploadValues(URL,
"POST", myNameValueCollection)
GetPageHTML = Encoding.UTF8.GetString(responseArray)
End Function

Nov 21 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
7572
by: James | last post by:
Hello group: I guessing there is no way to create an OLEDB linked table in Access to SQL Server, am I correct? Basically, I've currently migrated one of my Access database tables to SQL Server,...
0
2671
by: google | last post by:
My Crystal reports are being supplied the logon credentials via a C# code class that recursively loops through all the tables present in the reports and applies the login credentials (Servername,...
3
2545
by: rfontaine | last post by:
I have a virtual directory on IIS 5.0 to a remote share on a Windows 2003 file server. The "connect as" is a domain user account. The share as read permission for everyone and the NTFS permission...
3
15016
by: Milan Todorovic | last post by:
Hello, I need help. I have experience in ASP.NET programming, but this is my first dealing with Crystal Reports. I'm trying to make the most basic report purely for testing purposes: connect to...
2
1730
by: J-T | last post by:
Hi All, We have an asp.net application on a windows 2003 server which is part of a domain controller which my worksatis is too. We have impersonated in our applciation with a fixed identity...
0
1617
by: bonita | last post by:
I come across the error "CrystalDecisions.CrystalReports.Engine.LogOnException: Logon failed." After I move my asp.net code from the development platform (XP professional) to the production web...
0
2621
by: Marty Cruise | last post by:
I successfully deploy my application to 20 domain users. Only one new user is giving me a problem, although he can access all domain resources. When he clicks the installation link on the...
6
21282
by: Manuel | last post by:
Hi, Using the PIA "Microsoft Outlook 11 Object Library". I've noticed that the Logon method of the NameSpace Object is simply ignored. My Outlook 2003 is full updated. For example if I...
5
2326
by: drummerpunk10 | last post by:
Sorry if this is off topic, I haven't really used this forum a lot so I don't know where to put it. Anyways I have a game application that runs off a list games and users on a file, that I built in...
0
7108
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7181
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6847
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7352
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5445
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4875
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
618
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.