Re: HTTP Object and Retrieving HTML Programatically



On Oct 25, 8:41 pm, Paul <P...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
I am using ASP.Net 2.0 and VB.Net (although C#is ok also).

I want to create an object/method/function that will take a URL as an input
parameter and then return all of the HTML in that page.

I also want to return the HTTP header information (response object).

Does anyone have an insight as to any code samples or .Net objects I would
use to accomplish this?

TIA

Use WebRequest:

Dim PageUrl As String = "http://...";

Dim req As HttpWebRequest = CType(WebRequest.Create(PageUrl),
HttpWebRequest)
Dim enc As Encoding = Encoding.GetEncoding(1252)
Dim r As HttpWebResponse
Dim s As System.IO.StreamReader


r = CType(req.GetResponse(), HttpWebResponse) ' This is your response
s = New System.IO.StreamReader(r.GetResponseStream(), enc)

Dim html As String = s.ReadToEnd()

r.Close()
s.Close()

Response.Write(html)

.



Relevant Pages

  • httpwebrequest Vista Error
    ... I have used the httpwebrequest object to read an html file as stream from our ... ' Output is in html with line breaks between links. ... Dim Filecount As Integer ... ' Create a new 'HttpWebRequest' object to the mentioned URL. ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • HttpWebRequest
    ... Dim req As HttpWebRequest ... Dim newStream As IO.Stream ...
    (microsoft.public.dotnet.framework.aspnet)
  • Trying to login to web page with HttpWebRequest
    ... Given the following FORM definition contained in the default.asp html: ... Dim objRequest As HttpWebRequest = ... Dim myWriter As New StreamWriter ... Dim resTxt As String = newsr.ReadToEnd ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Mail Merge HTML Format Word 2002 XP SP3
    ... have now modified that code to send as HTML and if so how do I do this please. ... The body text format determines the standard used to display the text of the ... Microsoft Outlook provides three body text format options: ... Dim olApp As Outlook.Application ...
    (microsoft.public.word.mailmerge.fields)
  • Re: socket error
    ... It ended up with something to do with our Proxy configuration. ... but on the 2.0 box for some reason the httpwebrequest couldnt ... Yes I can visit that page directly through a browser on the server. ... >> | Dim returnstr As String ...
    (microsoft.public.dotnet.framework.aspnet)

Loading