471,047 Members | 1,274 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,047 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 4404
> 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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by SK | last post: by
1 post views Thread by Loane Sharp | last post: by

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.