How to re-send data from ASP

I was looking for a solution for a long time and finally I got it. The problem originates in need to resend data from an IPN processing script to another script. This is a main problem when integrating e.g. with PayPal. In PHP this is easy, as you can use cURL code. The problem however is with ASP code. It is not possible to use cURL in ASP as you know, so you cannot use this solution in case your IPN script is ASP.

The solution is to use objHttp object in ASP (VB.NET):
Dim objHttp: Set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP");
objHttp.open "POST", "https://yoursite.com/PAP4/script_to_receive_data.php", False;
objHttp.setRequestHeader "Content-type", "application/x-www-form-urlencoded";
objHttp.Send Request.Form;
Or in C#.NET:
string qString = Request.QueryString["pap_custom"];
string url = "https://yoursite.com/PAP4/plugins/PayPal/paypal.php?pap_custom=" + qString;
HttpWebRequest objHttp = (HttpWebRequest)WebRequest.Create(url);
objHttp.ContentType = "application/x-www-form-urlencoded";
objHttp.Method = "POST";
objHttp.KeepAlive = false;
objHttp.Credentials = System.Net.CredentialCache.DefaultCredentials;
byte[] _byteVersion = Encoding.ASCII.GetBytes(Request.Form.ToString());
Stream requestStream = objHttp.GetRequestStream();
requestStream.Write(_byteVersion, 0, _byteVersion.Length);
requestStream.Close();
 
The code above will create a POST request in ASP, fill it with data received (Request.Form) and send it to URL defined in second line.
 
Update: the first code seems to be outdated so here is one more equivalent how to do it in VB.net
 
Imports System
Imports System.IO
Imports System.Net
        
Using client As New Net.WebClient
   Dim PAPurl As String = "https://SOMETHING.postaffiliatepro.com/plugins/PayPal/paypal.php"
   client.UploadValues(PAPurl, "POST", Request.Form)
End Using
×