468,512 Members | 1,422 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

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 4371
> 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
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.