By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,696 Members | 1,462 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,696 IT Pros & Developers. It's quick & easy.

POSTing Data to another server

P: n/a
I am in a situation where I need to package some information from
Page1, submit it via POST to another server which will process the
information and then send the user to another page on my server
(Page2).

I have looked at HttpWebRequest (see code below) on numerous coding
websites but have not found a method that works. Does anyone have a
solution for this or has seen an example that works for this
situation?

Currently, I am using an HTML page that obviously goes away when it
performs the POST. I need the ASP.NET page to work the same way--send
the data and go away. The receiving server is configured to send data
back to a page on my server.

This is one very frustrating issue that I have with ASP.NET--the
postback architecture gets wrapped around itself for something like
this.
Thanks,
Mike

private void btnSubmit_Click(object sender, System.EventArgs e)
{
string bname = tbName.Text;
string baddr1 = tbAddress.Text;
string bcity = tbCity.Text;
string bstate = ddlState.SelectedItem.Value;
string bzip = tbZip.Text;
string phone = tbPhone.Text;
string email = tbEMail.Text;
string cctype = ddlCCType.SelectedItem.Value;
string cardnumber = tbCCNumber.Text;
string expmonth = ddlExpMonth.SelectedItem.Value;
string expyear = ddlExpYear.SelectedItem.Value;
string subtotal = lblCost.Text.Substring(1);
string tax = lblTax.Text.Substring(1);
string chargetotal = lblTotal.Text.Substring(1);

string postData = "bname=" + Server.UrlEncode(bname);
postData += "&baddr1=" + Server.UrlEncode(baddr1);
postData += "&bcity=" + Server.UrlEncode(bcity);
postData += "&bzip=" + Server.UrlEncode(bzip);
postData += "&phone=" + Server.UrlEncode(phone);
postData += "&email=" + Server.UrlEncode(email);
postData += "&cctype=" + Server.UrlEncode(cctype);
postData += "&cardnumber=" + Server.UrlEncode(cardnumber);
postData += "&expmonth=" + Server.UrlEncode(expmonth);
postData += "&expyear=" + Server.UrlEncode(expyear);
postData += "&subtotal=" + Server.UrlEncode(subtotal);
postData += "&tax=" + Server.UrlEncode(tax);
postData += "&chargetotal=" +
Server.UrlEncode(chargetotal);
postData += "&storename=XXXXXXXXXX";
postData += "&mode=payplus";
postData += "&txnorg=eci";
postData += "&bcountry=US";
postData += "&2000=submit";

HttpWebRequest postReq = (HttpWebRequest)
WebRequest.Create("https://staging.linkpt.net/lpc/servlet/lppay");
postReq.Method = "POST";
postReq.AllowAutoRedirect = false;
postReq.ContentType = "application/x-www-form-encoded";
postReq.ContentLength = postData.Length;

byte[] buffer = Encoding.UTF8.GetBytes(postData);
using (Stream reqst = postReq.GetRequestStream())
{
reqst.Write(buffer, 0, buffer.Length);
}
}
Jul 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.