Solved

Server.CreateObject("Msxml2.ServerXMLHTTP")

Posted on 2003-12-06
5
1,770 Views
Last Modified: 2013-12-16
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.
0
Comment
Question by:dbnewbie
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:mccainz2
ID: 9892542
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
0
 
LVL 1

Accepted Solution

by:
Lycaon earned 50 total points
ID: 9892768
If you're doing this in Visual Basic, you do not need the Server. part.  That's for ASP.

Simply use this, and you should get a valid object if you have that component installed.

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

Author Comment

by:dbnewbie
ID: 9892924
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.
0
 

Author Comment

by:dbnewbie
ID: 9892953
Never mind. Dumb request. Thanks.
0
 
LVL 1

Expert Comment

by:Lycaon
ID: 9894551
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
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now