These examples illustrate how to post data to the server, and retrieve the Web page either as string or file.
<% @LANGUAGE=VBSCRIPT %>
<% Option Explicit %>
<!-- #include file="asptearinclude.asp" -->
<html>
<head>
<META NAME="generator" CONTENT="Allaire HomeSite 4.0">
<title>Retrieval of POST page</title>
</head>
<body>
<%
Dim xObj, strResult, strUrl
' create the object
Set xobj = CreateObject("SOFTWING.ASPtear")
On Error Resume Next
' set a referrer, don't cache pages, supply a custom user agent and a timeout
xObj.Referrer = "http://www.vatican.va/"
xObj.ForceReload = True
xObj.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.0b2; Windows NT)"
xObj.ConnectionTimeout = 45
strUrl = Request.ServerVariables("SCRIPT_NAME")
strUrl = Left(strUrl,InStrRev(strUrl,"/")) & "formpost.asp"
strUrl = "http://" & Request.ServerVariables("SERVER_NAME") & strUrl
' URL, action, payload, filename, username, password
strResult = xobj.Retrieve(strUrl, Request_POST, "test=it", "", "")
HandleError
Response.Write "<font color=""red"">" & strResult & "</font>"
Response.Write "<br><b>Headers:</b><br><PRE>" & xObj.Headers & "</PRE>"
%>
</body>
</html>
<% @LANGUAGE=VBSCRIPT %>
<% Option Explicit %>
<!-- #include file="asptearinclude.asp" -->
<%
Dim xObj, strUrl, bDoneSuccessfully, strFile
Set xobj = CreateObject("SOFTWING.ASPtear")
On Error Resume Next
xObj.Referrer = "http://www.vatican.va/"
xObj.ForceReload = True
strUrl = Request.ServerVariables("SCRIPT_NAME")
strUrl = Left(strUrl,InStrRev(strUrl,"/")) & "formpost.asp"
strUrl = "http://" & Request.ServerVariables("SERVER_NAME") & strUrl
strFile = Server.MapPath("output.txt")
' URL, action, payload, filename, username, password
bDoneSuccessfully = xobj.Save(strUrl, Request_POST , "test=it", strFile, "", "")
HandleError
If bDoneSuccessfully Then Response.Write "Written successfully"
%>
<SCRIPT language="vbscript" runat="server">
' Written by: Christoph Wille
' Last updated: 5/22/2001
' Constant declarations
Const Request_POST = 1
Const Request_GET = 2
Const Request_HEAD = 3
' Returns False if no error, True if error was handled
Function HandleError()
HandleError = False
If Err.Number <> 0 Then
HandleError = True
Response.Write "<b>"
If Err.Number >= 400 Then
Response.Write "Server returned error: " & Err.Number & " " & err.description
Else
Response.Write "Component/WinInet error: " & Err.Description
End If
Response.Write "</b>"
Response.End
End If
Err = 0
End Function
Function HandleErrorEx(ByVal bEndResponse)
HandleError = False
If Err.Number <> 0 Then
HandleError = True
Response.Write "<b>"
If Err.Number >= 400 Then
Response.Write "Server returned error: " & Err.Number & " " & err.description
Else
Response.Write "Component/WinInet error: " & Err.Description
End If
Response.Write "</b>"
If (bEndResponse) Then Response.End
End If
Err = 0
End Function
</SCRIPT>
<PRE>
<%
' retrieve and write all headers back to the user
Response.Write Request.ServerVariables("ALL_HTTP")
%>
</PRE>
<%
' display the posted variables
Response.Write "<b>" & Request.Form("test") & "</b>"
%>
<form method=post action="">
<input type=text name="test">
<input type=submit>
</form>