473,549 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using WebClient to get the actual file name.

Hi,

I've been working on an application to do some 'scraping' of web
content, using the WebClient class. I'm using code rather like the
following..

Dim objWebClient As New WebClient
Dim strURL As String = CType(URL, String)
Dim aRequestedHTML( ) As Byte
Dim objUTF8 As New UTF8Encoding
Dim strRequestedHTM L As String

aRequestedHTML = objWebClient.Do wnloadData(strU RL)
strRequestedHTM L = objUTF8.GetStri ng(aRequestedHT ML)

Return strRequestedHTM L

However, if I enter the url, say
http://web.archive.org/web/200306221...odhouse.co.uk/

the returned html is not the page that I requested (as viewed in the
browser), but rather a error page saying that the page has not been
found.

Does anyone know why this may be the case? My ideas so far have been
that the web browser (and server) and work out to send the correct
page, while the Web Client class isn't actually specifying a page at
the end of the url..

If anyone has an idea on this problem I would like to hear it, the
deadline for this project is coming up fast and this is a stumbling
block that I need to overcome, once this is done then its (hopefully!)
all plain sailing from here.

Thanks for your time

Chris Williams (chris (at) oxymoron-failsafe.com)
Nov 21 '05 #1
1 3109
If you are wanting the content of the page, here are two ways of getting it.

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim wc As New System.Net.WebC lient
Dim ascii As System.Text.Enc oding = System.Text.Enc oding.ASCII
Dim Results As Byte() =
wc.DownloadData ("http://web.archive.org/web/20030622145316/http://www.lynwoo
dhouse.co.uk/")
Dim asciiChars(Resu lts.GetLength(0 )) As Char
ascii.GetChars( Results, 0, Results.Length, asciiChars, 0)
Dim asciiString As New String(asciiCha rs)
MsgBox(asciiStr ing)
End Sub
Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
Dim myRequest As System.Net.WebR equest =
System.Net.WebR equest.Create(" http://web.archive.org/web/20030622145316/http
://www.lynwoodhous e.co.uk/")
Dim myResponse As System.Net.WebR esponse = myRequest.GetRe sponse()
Dim myStream As System.IO.Strea m = myResponse.GetR esponseStream
Dim sr As System.IO.Strea mReader = New
System.IO.Strea mReader(myStrea m)
MsgBox(sr.ReadT oEnd)
myStream.Close( )
myResponse.Clos e()
End Sub

"Scampi" <sc****@lyingsa ckofshit.com> wrote in message
news:b7******** *************** ***@posting.goo gle.com...
Hi,

I've been working on an application to do some 'scraping' of web
content, using the WebClient class. I'm using code rather like the
following..

Dim objWebClient As New WebClient
Dim strURL As String = CType(URL, String)
Dim aRequestedHTML( ) As Byte
Dim objUTF8 As New UTF8Encoding
Dim strRequestedHTM L As String

aRequestedHTML = objWebClient.Do wnloadData(strU RL)
strRequestedHTM L = objUTF8.GetStri ng(aRequestedHT ML)

Return strRequestedHTM L

However, if I enter the url, say
http://web.archive.org/web/200306221...odhouse.co.uk/

the returned html is not the page that I requested (as viewed in the
browser), but rather a error page saying that the page has not been
found.

Does anyone know why this may be the case? My ideas so far have been
that the web browser (and server) and work out to send the correct
page, while the Web Client class isn't actually specifying a page at
the end of the url..

If anyone has an idea on this problem I would like to hear it, the
deadline for this project is coming up fast and this is a stumbling
block that I need to overcome, once this is done then its (hopefully!)
all plain sailing from here.

Thanks for your time

Chris Williams (chris (at) oxymoron-failsafe.com)

Nov 21 '05 #2

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

Similar topics

3
2064
by: brianinbox | last post by:
Hi, I've been trying to upload file using webclient.uploadfile method from my IIS webserver to an Apache webserver without any success. On the Apache server (server that receives the incoming file) I have a simple php script, getFile.php to receive the file. The script look like this: <?php $uploadDir = '/var/www/Incoming/'; $uploadFile =...
4
2293
by: brianinbox | last post by:
Hi, I've been trying to upload file using webclient.uploadfile method from my IIS webserver to an Apache webserver without any success. On the Apache server (server that receives the incoming file) I have a simple php script, getFile.php to receive the file. The script look like this: <?php $uploadDir = '/var/www/Incoming/'; $uploadFile...
3
2461
by: Bruno Otero | last post by:
Hi! I have a program that excutes the following code: DirectoryInfo diretorio = new DirectoryInfo(@"C:\teste"); FileInfo arquivos = diretorio.GetFiles("*.xml"); for(int contador=0;contador<arquivos.Length;contador++) { lblMensagem.Text = "Uploading files... ";
1
5488
by: Sven Putze | last post by:
my target: I want to upload a file via HTTP Post and show the user a progress bar my 1st try: I´ve used WebClient.UploadFile and WebClient.UploadData, they work fine but I don't know any way to get the actual amount of transferred bytes, so what should I show on the
6
12220
by: genc ymeri | last post by:
Hi, We are struggeling to upload a file through a C# webClient into JBoss web server. Meanwhile we are able to upload a file from the webserver itself. The problem is only with C# webClient . The code is pretty simple. string uriString = saveTargetToAddress.Text; string postData = textOutput.Text; try
8
8998
by: DEWright_CA | last post by:
Why does WebClient.DownloadFile loose my completed path? Ok, I have a function in my app then when my button is clicked it checks to see if the files come from a local drive or a http address. The portion of the code that pulls from the drive works great, but when the http address is active it changes the originating path to my...
4
12692
by: Natalia | last post by:
Hello, I need to provide the ability to post file and some form elements via our website (asp.net) to the third party website (asp page). On http://aspalliance.com/236#Page4 - I found great advices but still having troubles... it might some obvious error that I am making but I just dont see it. ==================FIRST -...
3
3528
by: Nathan | last post by:
Have a strange problem. Creating a windows service running under the Local Sytem account. I have a Webclient that downloads a file from the internet. The code works fine if executed from a windows form but when i execute it in a windows service i get the following error: The proxy name could not be resolved: 'macc4' 'macc4' is a proxy...
5
4994
by: benmess | last post by:
This code snippet works fine on a localhost because the file you upload resides on the host machine (where FileServer.aspx is a new page invoked from the UploadFile call) function UploadGeneralFile(ByVal sURL as string,ByVal sFilename As String) Dim client As New System.Net.WebClient Dim sHTTPURL As String Dim req As...
0
7548
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7743
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7832
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6074
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5391
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3518
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3499
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1083
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.