Retrieve Server Response using XMLHTTP

by Anshoo Arora ON August 10, 2009 · Posted In All, QTP/Web, VBScript · 3 comments

I recently received the following question in my mailbox yesterday: Is it possible to retrieve the text of a page without physically opening it?

Yes, it’s possible to retrieve the document text without physically opening the page. It can be done though an XMLHTTP Request. XMLHTTP is short for Extensible Markup Language HyperText Transfer Protocol. “The XMLHttpRequest object implements an interface exposed by a scripting engine that allows scripts to perform HTTP client functionality, such as submitting form data or loading data from a server.”1

In the snippet below, I’ve created a simple mechanism to retrieve server response from this blog. The ‘OPEN’ method is used to assign a method (GET, POST, HEAD) of the pending request. The ‘SEND’ method sends the request (as detailed in the Open method) to the server.

Dim oXMLHTTP
 
Set oXMLHTTP = CreateObject("Microsoft.XMLHttp")
 
With oXMLHTTP
    .open "GET", "http://www.relevantcodes.com", False
    .send
 
    Reporter.ReportEvent micInfo, "Status", .statusText
    Reporter.ReportEvent micInfo, "Response", .responseText
End with
 
Set oXMLHTTP = Nothing
XMLHTTP Request Status

XMLHTTP Request Status

XMLHTTP Request Response

XMLHTTP Request Response

References

  1. The XMLHTTPRequest Object
  2. The XMLHTTPRequest Object

Subscribe to Relevant Codes (by Anshoo Arora)

Hello! We're always posting interesting articles on Relevant Codes. Why not subscribe so you don't miss out?

Leave a Comment

{ 3 comments… read them below or add one }

Bibek Khatiwara December 23, 2009 at 5:05 am

Ya Vishal..it’s working fine..

Dim oXMLHTTP
Set oXMLHTTP = CreateObject( “Microsoft.XMLHttp” )

With oXMLHTTP
.open “GET”, “http://www.google.co.in/”, False
.send

Stats=.statusText

msgbox Stats
End with

Set oXMLHTTP = Nothing

Reply

Anshoo Arora September 8, 2009 at 4:58 pm

Hi Vishal,

Actually, there can be multiple reasons for this error. Could you please share with me the code that you executed and the browser(s) installed on your system?

In the meantime, I would recommend you to read the following discussions:

1. XMLHTTPRequest – Permission Denied Error
2. How do I read the contents of a remote web page?
3. Problem using MS XMLHTTPRequest via https
4. StackOverflow.com: VBScript, MSXML and Namespaces

Regards,

Anshoo

Reply

Vishal CH September 7, 2009 at 11:49 pm

Hi Anshoo,

When i run the above code snippet i m getting an error ” Acess is denied ” at ‘.Send’ line cld u plz re look into it or what can i do for that?

Thanks in advance,

Vishal

Reply

Previous post:

Next post: