Solved

Server.CreateObject("Msxml2.ServerXMLHTTP")

Posted on 2003-12-06
5
1,773 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…

919 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

20 Experts available now in Live!

Get 1:1 Help Now