0

我在 ASP.net(C#) 中创建了 2 个页面。第一个(称为 shoppingcart.asp)有一个立即购买按钮。第二个(称为 processpay.asp)只是等待 google checkout 向其发送 HTTP 请求以处理付款。我想做的事情是向谷歌结帐发送一个 post 语句,其中包含我想传递回 processpay.asp 的几个变量(即 clientid=3&itemid=10),但我不知道如何格式化 POST HTTP 语句或我必须在 google checkout 中更改哪些设置才能使其正常工作。

任何想法将不胜感激。

4

3 回答 3

2

Google Checkout 有示例代码和关于如何将其与任何 .NET 应用程序集成的教程:

确保检查标题为“将示例代码集成到您的 Web 应用程序”的部分。


但是,如果您更喜欢使用服务器端 POST,您可能需要检查以下提交 HTTP 帖子并将响应作为字符串返回的方法:

using System.Net;

string HttpPost (string parameters)
{ 
   WebRequest webRequest = WebRequest.Create("http://checkout.google.com/buttons/checkout.gif?merchant_id=1234567890");
   webRequest.ContentType = "application/x-www-form-urlencoded";
   webRequest.Method = "POST";

   byte[] bytes = Encoding.ASCII.GetBytes(parameters);

   Stream os = null;

   try
   { 
      webRequest.ContentLength = bytes.Length;
      os = webRequest.GetRequestStream();
      os.Write(bytes, 0, bytes.Length);      
   }
   catch (WebException e)
   {
      // handle e.Message
   }
   finally
   {
      if (os != null)
      {
         os.Close();
      }
   }

   try
   { 
      // get the response

      WebResponse webResponse = webRequest.GetResponse();

      if (webResponse == null) 
      { 
          return null; 
      }

      StreamReader sr = new StreamReader(webResponse.GetResponseStream());

      return sr.ReadToEnd().Trim();
   }
   catch (WebException e)
   {
      // handle e.Message
   }

   return null;
} 

参数需要以如下形式传递:name1=value1&name2=value2

于 2009-12-31T01:01:05.613 回答
0

代码可能最终看起来像这样:

GCheckout.Checkout.CheckoutShoppingCartRequest oneCheckoutShoppingCartRequest =
  GCheckoutButton1.CreateRequest();

oneCheckoutShoppingCartRequest.MerchantPrivateData = "clientid=3";

GCheckout.Checkout.ShoppingCartItem oneShoppingCartItem =
  new GCheckout.Checkout.ShoppingCartItem();
oneShoppingCartItem.Name = "YourProductDisplayName";
oneShoppingCartItem.MerchantItemID = "10";

oneCheckoutShoppingCartRequest.AddItem(oneShoppingCartItem);
于 2010-11-29T16:48:29.810 回答
0

昨天我使用http://www.codeproject.com/KB/aspnet/ASP_NETRedirectAndPost.aspx发送帖子数据,它工作正常

于 2011-09-13T08:12:39.083 回答