protected void shopBasketCheckout_OnServerClick(object source,EventArgs e)
{
string postData = "";
postData += "currency_code=GBP";
postData += "&cmd=_cart";
postData += "[email protected]";
postData += "&upload=1";
postData += "&cancel_return=www.davidmillington.net";
DataTable dtBasket = getBasketDt();
double total = 0.00;
for(int i = 0; i < dtBasket.Rows.Count; i++)
{
postData += "&item_name_" + (i + 1) + "=" +
dtBasket.Rows[i]["name"];
postData += "&quantity_" + (i + 1) + "=" +
dtBasket.Rows[i]["quantity"];
postData += "&amount_" + (i + 1) + "=" +
Convert.ToDouble(dtBasket.Rows[i]["price"]);
total += (Convert.ToDouble(dtBasket.Rows[i]
["price"]) * Convert.ToInt32(dtBasket.Rows[i]["quantity"]));
if(i == dtBasket.Rows.Count - 1)
{
postData += "&shipping_" + (i + 1) + "=" + calcDeliveryCost(total);
}
else
{
postData += "&shipping_" + (i + 1) + "=0.00";
}
postData += "&shipping2_" + (i + 1) + "=0.00";
postData += "&handling_" + (i + 1) + "=0.00";
}
postData += "&handling=" + calcDeliveryCost(total);
byte[] data = Encoding.ASCII.GetBytes(postData);
HttpWebRequest ppRequest = (HttpWebRequest)
WebRequest.Create("https://www.paypal.com/cgi-bin/webscr");;
ppRequest.Method = "POST";
ppRequest.ContentType = "application/x-www-form-
urlencoded";
ppRequest.ContentLength = data.Length;
//发送
Stream ppStream = ppRequest.GetRequestStream();
ppStream.Write(data, 0, data.Length);
ppStream.Close();
//接收
HttpWebResponse ppResponse = (HttpWebResponse)ppRequest.GetResponse();
StreamReader sr = new StreamReader(ppResponse.GetResponseStream());
string strResult = sr.ReadToEnd();
sr.Close();
//输出到屏幕
Response.Clear();
Response.Write(strResult);
Response.End();
}