Link to home
Start Free TrialLog in
Avatar of dbnewbie
dbnewbie

asked on

Server.CreateObject("Msxml2.ServerXMLHTTP")

I'm trying to obtain the contents (XHTML, HTML, JavaScript, etc.) of a website. How do I get the source code of a particular webpage? The following gives me an error (object required) in VB6:

Set objHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP")

Please advise.
Avatar of mccainz2
mccainz2

alternatively to acquire the source behind a page :

1.add a 'Microsoft Internet Transfer Control' to your form and...

Dim sSrc As String
sSrc = Inet1.OpenURL("cnn.com")
Text1.Text = sSrc
ASKER CERTIFIED SOLUTION
Avatar of Lycaon
Lycaon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dbnewbie

ASKER

Doh! You're right, it is ASP.  Lycaon, can you please complete the code to grab the site's source code and assign it to a string? Thanks.
Never mind. Dumb request. Thanks.
dbnewbie,

Sorry I didn't add the entire code earlier, I was at work and didn't have my code with me.  The following should work.

objHTTP.Open "GET", URL, False, "SomeUser", "SomePass"
' objHTTP.Open Method, URLToGet, Async, UserName, Password
' Method and URLToGet are REQUIRED.  Async defaults to True, however, since you are not using a reference to the XML library, you do not have any events to work with.  By setting Async to False, you cause the program to 'pause' until either the URL is retreived, or it encounters an error.

objHTTP.SetRequestHeader "Content-type", "text/html"
' Sets the expected content type, I believe

objHTTP.Send
' Sends the request.


rspText = objHTTP.ResponseText
' Places the retreived URL (usually text) into a variable

Set objHTTP = Nothing
'If you're not going to use the object again, set it to nothing

I've checked this code myself, and it works fine.  As a side note, it appears to use IE's User-Agent header (sites like google refuse to send their pages to unknown user agents)

Another note, in my code it throws a fit unless the URL starts with http://

Lycaon