VB icon

ASP Post Forward

Email
Submitted on: 1/1/2015
By: Andrew Friedl  
Level: Intermediate
User Rating: By 3 Users
Compatibility: ASP (Active Server Pages)
Views: 2
 
     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.)
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
' for :ASP Post Forward
'**************************************
Free as long as copyright info remains intact.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: ASP Post Forward
' Description: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.)
' By: Andrew Friedl
'
' Inputs:An HTML form post.
'
' Returns:The exact response from the forwarded server to the original ASP page.
'
' Assumes:You webserver can result the IP address of the forwarded server.
'
' Side Effects:My not be suitable for posting binary data, form posts work fine though.
'**************************************

<%@ 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
%>


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.