473,321 Members | 1,622 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,321 software developers and data experts.

GetResponseStream

Hello,

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?

Thanks

mwPageRequest = CType(WebRequest.Create(msURL),
HttpWebRequest)
mwPageRequest.Timeout = miTimeout
mwPageRequest.AllowAutoRedirect = True
mwPageResponse = mwPageRequest.GetResponse()
Dim r As New
StreamReader(mwPageResponse.GetResponseStream())
msPage = r.ReadToEnd()
mwPageResponse.Close()
r.Close()
Nov 20 '05 #1
1 4507
> 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"), _
HttpWebRequest)
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"), _
HttpWebRequest)
wr.Timeout = 5000
wr.AllowAutoRedirect = True

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

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

End If

--
Eduardo A. Morcillo [MS MVP VB]
http://www.mvps.org/emorcillo
Nov 20 '05 #2

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

Similar topics

0
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...
2
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 (); ...
7
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 =...
2
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 =...
1
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
9
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...
2
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...
1
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...
16
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.