The following are code samples for ASPTear 1.0.
Basics
The ASPTear component is 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 do not need to supply an Username and Password, leave them empty (""). Thus, the simplest request looks like this:
strRetVal = xObj.Retrieve("http://www.alphasierrapapa.com/iisdev/",2,"","","")
Notice that a document is not supplied - the component supports redirects.
For a more sophisticated example: 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 final method to discuss is how to access SSL-secured items - simply replace http:// with https:// in the strUrl parameter.
ASP Sample
This example uses the component to retrieve the Google homepage and return it to the client.
<%
Const Request_POST = 1
Const Request_GET = 2
Set xobj = CreateObject("SOFTWING.ASPtear")
Response.ContentType = "text/html"
On Error Resume Next
' URL, action, payload, username, password
strRetval = xobj.Retrieve("http://www.google.com", Request_GET, "", "", "")
If Err.Number <> 0 Then
Response.Write "<b>"
If Err.Number >= 400 Then
Response.Write "Server returned error: " & Err.Number
Else
Response.Write "Component/WinInet error: " & Err.Description
End If
Response.Write "</b>"
Response.End
End If
Response.Write strRetval
Set xobj = Nothing
%>
Article ID: 109, Created On: 11/6/2008, Modified: 4/22/2011