Classic ASP Screenscraping
page 1 of 1
Published: 25 Mar 2004
Unedited - Community Contributed
Abstract
Here is a function that you can use to POST and return information to/from a remote site. Microsoft has kindly created a lovely component for working with XML that has a nice set of tools (as a side effect) for communicating with remote servers, the script uses these tools to send variables and receive the HTTP output.
by Chris Garrett
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 25848/ 86

Classic ASP Screenscraping

Here is a function that you can use to POST and return information to/from a remote site.

VIEW SOURCE
/chrisg/tools/view-sendpost.asp

DOWNLOAD SOURCE
/chrisg/tools/download.asp?file=sendpost.asp

SEE IT IN ACTION
/chrisg/tools/sendpost.asp

If you try the above "see it in action link" you will see the script has POSTed the name/value pair of "test=Yay!", and this has been reflected in the remote page that has been called (outputvars.asp, an example from a previous article) which outputs all the current request variables. Take a look at the results and you will also see the REQUEST_METHOD was POST.

How was it done?

Microsoft has kindly created a lovely component for working with XML that has a nice set of tools (as a side effect) for communicating with remote servers, the script uses these tools to send variables and receive the HTTP output.

The script

The script consists of a function call will supplies a URL and the information to post to a function called "sendPost".

SendPost creates an instance of the XMLHTTP object (line 9), and then uses the Open method (line 16) with the parameters "POST" to say we want to post the information (change to GET if you want to use GET) and the URL we wish to talk to.

Because I am using POST I need to add the header in line 17, if you are using GET ommit this line.

Lines 18 and 21 are where we send the information and the response is returned to our script.

Extending the script

This as it stands is a reusable function for posting and receiving the response. Possible uses are submitting information to multiple search engines and returning the results, or posting competition entries to a third party while retaining the visitor on your own site.

If you want to work with the response you will probably need to use regular expressions, which is outside the scope of this article, check out the following links.



User Comments

Title: doesn't work   
Name: Dean
Date: 2009-10-07 11:25:19 AM
Comment:
see it in action produces a "resource not found" error, asp alliance doesn't stand behind this junk
Title: SEE IT IN ACTION   
Name: Everson
Date: 2008-06-13 8:36:44 AM
Comment:
The url in
SEE IT IN ACTION
is not working
Title: Learn ASP   
Name: Racheal
Date: 2006-06-21 5:07:22 AM
Comment:
Good one.... but not a good location for beginners to get started .......so how can one learn ASP here????

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2017 ASPAlliance.com  |  Page Processed at 2017-03-29 9:20:42 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search