473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.



I have two questions:

1. How can I download a webpage only if the content type is "text"
without actually downloading and checking it?

2. When I download the page (using the code that I have posted here),
it changes the content of the page. Like if the page has abcd%40efg
it makes it abcd@efg, or this is atleast what I get in my msPage.
What do I need to do so that I get abcd%40efg, and not abcd@efg?


mwPageRequest = CType(WebRequest.Create(msURL),
mwPageRequest.Timeout = miTimeout
mwPageRequest.AllowAutoRedirect = True
mwPageResponse = mwPageRequest.GetResponse()
Dim r As New
msPage = r.ReadToEnd()
Nov 20 '05 #1
1 4509
> 1. How can I download a webpage only if the content type is "text"
without actually downloading and checking it?

Use the HEAD method and check the ContentType. Then if it matches the
content type you want download the entire page.

Dim wr As HttpWebRequest
Dim resp As HttpWebResponse

wr = DirectCast(HttpWebRequest.Create("http://www.yahoo.com"), _
wr.AllowAutoRedirect = True
wr.Timeout = 5000
wr.Method = "HEAD"

resp = DirectCast(wr.GetResponse(), HttpWebResponse)

If resp.ContentType = "text/html" Then

wr = DirectCast(HttpWebRequest.Create("http://www.yahoo.com"), _
wr.Timeout = 5000
wr.AllowAutoRedirect = True

resp = DirectCast(wr.GetResponse(), HttpWebResponse)

Dim reader As New IO.StreamReader(resp.GetResponseStream())

End If

Eduardo A. Morcillo [MS MVP VB]
Nov 20 '05 #2

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

Similar topics

by: Mattias | last post by:
I'm saving pictures on my harddrive from our webcam with GetResponseStream() .. Everything works fine, but after approximately 1h identical images are being saved. I checked the webpage but those...
by: SK | last post by:
Hi, I am not able to convert the response stream from HttpWebResponse into bytes properly. Here is the relevent code - HttpWebResponse response = (HttpWebResponse)request.GetResponse (); ...
by: SKG | last post by:
Iam trying to read an xml file from a website and i get junk characters. But when i open the same file in browser everything is fine. here is the snippet of the code WebRequest objRequest =...
by: Andres Romero | last post by:
I'm using the next code to get the source code from a web page and save it to disk, all works fine except that the width property is lost: wrRequest =...
by: Loane Sharp | last post by:
Hi there I'm attempting to download a file from our server programmatically using an internet connection. The code is given below. Any ideas why it fails? Best regards
by: ThePants | last post by:
Hi, given the following code, I've been successful in grabbing pages for parsing, but for a certain page template (containing a particular piece of code) the stream always ends right after that...
by: Joe | last post by:
The example in the msdn shows how to write an image to the OutputStream and the example for GetResponseStream() shows how to read the stream and write it to the console. Unfortunately there is no...
by: vito16 | last post by:
Hi, I have some C# code for a console application that was correctly grabbing pages until recently were the data is now incomplete. I am needing to grab all information including sponsored links...
by: GVNPublic123 | last post by:
Hello, What I am trying to do, is login YouTube using C# (HTTPWebRequest). The problem is, I don't really know how to do it. Is there any URL I could fill using the username and pass and...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
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,...
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...
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...

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.