Important alert: (current site time 11/23/2014 7:36:33 PM EDT)
 

VB icon

ASP Post Forward

Email
Submitted on: 5/15/2003 2:25:32 PM
By: Andrew Friedl 
Level: Intermediate
User Rating: By 3 Users
Compatibility: ASP (Active Server Pages)
Views: 11987
(About the author)
 
     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!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' 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.
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=8368&lngWId=4'for details.'**************************************

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


Other 2 submission(s) by this author

 


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

5/16/2003 9:32:09 AM

Andrew,

5 globes for a clever idea!

Kudos to you Bro!

-Blow-
(If this comment was disrespectful, please report it.)

 
5/16/2003 4:33:16 PMICode

Nice! Great Idea!
(If this comment was disrespectful, please report it.)

 
6/30/2003 10:18:54 PM

hi,
I guess i need your help .... how to use winhttp with asp pages to maintain a few connection link with a payment gateway server (send-and-receive data) with more than 1 asp page?

Thanks and Regards.
ys_foo@unifiedcomms.com
(If this comment was disrespectful, please report it.)

 
10/13/2003 4:51:09 AMFirebirdDE

Using vb-code to convert binary to ascii is VERY slow. Try using the ADO functions instead or use MSXML2.ServerXMLHTTP to download data.
(If this comment was disrespectful, please report it.)

 
2/21/2005 8:05:29 AM

doesn't work for me.. error:

WinHttp.WinHttpRequest (0x80072F76)
The requested header was not found

why?
(If this comment was disrespectful, please report it.)

 

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.