?
Solved

Server.CreateObject("Msxml2.ServerXMLHTTP")

Posted on 2003-12-06
5
Medium Priority
?
1,796 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 200 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. 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 :…
The purpose of this video is to demonstrate how to Import and export files in 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 : Click on Too…
Suggested Courses
Course of the Month9 days, 5 hours left to enroll

764 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