POSTing Data to another server

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • someone

    #1

    POSTing Data to another server

    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.EventArg s e)
    {
    string bname = tbName.Text;
    string baddr1 = tbAddress.Text;
    string bcity = tbCity.Text;
    string bstate = ddlState.Select edItem.Value;
    string bzip = tbZip.Text;
    string phone = tbPhone.Text;
    string email = tbEMail.Text;
    string cctype = ddlCCType.Selec tedItem.Value;
    string cardnumber = tbCCNumber.Text ;
    string expmonth = ddlExpMonth.Sel ectedItem.Value ;
    string expyear = ddlExpYear.Sele ctedItem.Value;
    string subtotal = lblCost.Text.Su bstring(1);
    string tax = lblTax.Text.Sub string(1);
    string chargetotal = lblTotal.Text.S ubstring(1);

    string postData = "bname=" + Server.UrlEncod e(bname);
    postData += "&baddr1=" + Server.UrlEncod e(baddr1);
    postData += "&bcity=" + Server.UrlEncod e(bcity);
    postData += "&bzip=" + Server.UrlEncod e(bzip);
    postData += "&phone=" + Server.UrlEncod e(phone);
    postData += "&email=" + Server.UrlEncod e(email);
    postData += "&cctype=" + Server.UrlEncod e(cctype);
    postData += "&cardnumbe r=" + Server.UrlEncod e(cardnumber);
    postData += "&expmonth= " + Server.UrlEncod e(expmonth);
    postData += "&expyear=" + Server.UrlEncod e(expyear);
    postData += "&subtotal= " + Server.UrlEncod e(subtotal);
    postData += "&tax=" + Server.UrlEncod e(tax);
    postData += "&chargetot al=" +
    Server.UrlEncod e(chargetotal);
    postData += "&storename=XXX XXXXXXX";
    postData += "&mode=payplus" ;
    postData += "&txnorg=ec i";
    postData += "&bcountry= US";
    postData += "&2000=subm it";

    HttpWebRequest postReq = (HttpWebRequest )
    WebRequest.Crea te("https://staging.linkpt. net/lpc/servlet/lppay");
    postReq.Method = "POST";
    postReq.AllowAu toRedirect = false;
    postReq.Content Type = "applicatio n/x-www-form-encoded";
    postReq.Content Length = postData.Length ;

    byte[] buffer = Encoding.UTF8.G etBytes(postDat a);
    using (Stream reqst = postReq.GetRequ estStream())
    {
    reqst.Write(buf fer, 0, buffer.Length);
    }
    }
Working...