Solved

Server.CreateObject("Msxml2.ServerXMLHTTP")

Posted on 2003-12-06
5
1,790 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

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.
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

691 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