Search Tools Links Login

ASP Post Forward


This simple ASP script uses WinHTTP to forward an ASP POST to an entirely different server and retun the content to the original ASP page. It is useful for serving up client content from another http source. In my case it is used to serve PDF reports from Java Server Pages to an ASP front end website. With this script you can server the content to the external user while the origin of the content itself appears to be the internet server. (People are unaware of the Apacha Tomcat Server running JSP and wont try to hack into it.)

Original Author: Andrew Friedl

Inputs

An HTML form post.

Assumptions

You webserver can result the IP address of the forwarded server.

Returns

The exact response from the forwarded server to the original ASP page.

Side Affects

My not be suitable for posting binary data, form posts work fine though.

API Declarations

Free as long as copyright info remains intact.

Code

<%@ LANGUAGE = "VBScript" %><%
' Module : ASP POST Forward
' Author : Andrew Friedl
' Copyright: 2003.04.15 - Andrew Friedl
' License : License is hereby granted for commercial and
'   non-commercial use as long as the authors
'   information and copyright remains intact.
Dim http: Set http=Server.CreateObject("WinHttp.WinHttpRequest.5")
Private Function ConvertBin(bsString)
Dim nIndex
For nIndex = 1 to LenB(bsString)
ConvertBin = ConvertBin & Chr(AscB(MidB(bsString,nIndex,1)))
Next
End Function
http.Open "POST", "http://TargetServer/TargetPage.ASP", False
http.SetTimeouts 60000, 60000, 60000, 60000
http.SetRequestHeader "Content-Type", Request.ServerVariables("CONTENT_TYPE")
http.Send Trim(ConvertBin(Request.BinaryRead( Request.TotalBytes )))
Response.Clear
Response.ContentType = http.GetResponseHeader("content-type")
Response.BinaryWrite http.ResponseBody
Response.End
%>

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 87 times

Categories

ASP/ HTML

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.