Friday, July 13, 2007

AspTear Component - free

What about a simple and cheap (=totally free) component for "tearing" web pages from a server? If you have searched for such a solution, then you are right here: AspTear allows you to retrieve web pages from servers easily with a bunch of features.

Here's a list of the component's main features:

  • Supports GET and POST
  • Send query strings and POST data to the server
  • Access HTTP and HTTPS resources
  • Log in to secured sites with username/password

Basics

So how does it work? Currently, the component is really very simple as it supports only one method (server-side VBScript pseudocode given here):

Const Request_POST = 1
Const Request_GET = 2
Set xObj = Server.CreateObject("SOFTWING.AspTear")
strRetVal = xObj.Retrieve(strUrl, nRequestType, strQueryString|strPostData, _
strUsername, strPassword)
The file retrieved is returned as method return value (strRetVal; errors are returned with exceptions - see the samples). If you don't need to supply Username and Password, leave them empty (""). Thus, the simplest request looks like this:
strRetVal = xObj.Retrieve("http://www.alphasierrapapa.com/iisdev/",2,"","","")
Notice that I did not supply a document - the component supports redirects! Now let's get a little bit more sophisticated: POST a form to the server with form data. How is this form data formatted? It needs to have the following form,
variable1=value1&variable2=value2...
where value1 to n need to be URL-encoded. To URL-encode a string value, use Server.URLEncode (this is also mandatory for querystrings):
strPostData = "Name=" & Server.URLEncode("Christoph Wille") & _
"&goto=" & Server.URLEncode("http://www.alphasierrapapa.com/")
The call to Retrieve now looks like this:
strRetVal = xObj.Retrieve("http://www.alphasierrapapa.com/",1,strPostData,"","")
The last thing to discuss is how to access SSL-secured items - it is as simple as replacing http:// with https:// in the strUrl parameter!

No comments:

eXTReMe Tracker