本文介绍了谷歌Checkout的HTTP POST与ASP.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2页我在ASP.net(C#)创建的。第一个(被称为shoppingcart.asp)有一个现在就买按钮。第二个(称为processpay.asp)只是等待谷歌结帐发送一个HTTP请求到它处理付款。我愿做发个帖子声明,谷歌结帐一对夫妇的变数,我想传递回processpay.asp(即客户端ID = 3及的itemid = 10),但我不知道如何HTTP POST格式化我有陈述或者什么设置在谷歌结帐改变,使其工作。

I have 2 pages I created in ASP.net(C#). The first one(called shoppingcart.asp) has a buy it now button. The second one(called processpay.asp) just waits for google checkout to send an HTTP request to it to process the payment. What I would like to do send a post statement to google checkout with a couple of variables that I want passed back to processpay.asp(ie clientid=3&itemid=10), but I don't know how to format the POST HTTP statement or what settings I have to change in google checkout to make it work.

任何意见将大大AP preciated。

Any ideas would be greatly appreciated.

推荐答案

谷歌Checkout的样品具有code,以及如何将它与任何.NET应用程序集成的教程:

Google Checkout has sample code and a tutorial on how to integrate it with any .NET application:



  • Google Checkout API - Google Checkout Sample Code for .NET

请一定要检查标题为:<一个href=\"http://$c$c.google.com/apis/checkout/samples/Google%5FCheckout%5FSample%5F$c$c%5FNET.html#googleCheckoutSample$c$cStepsToIntegrate\"相对=nofollow>集成示例code到你的Web应用程序。

Make sure to check the section titled: "Integrating the Sample Code into your Web Application".

然而,如果你preFER使用服务器端的POST,您可能要检查下列方法,提交一个HTTP POST和返回响应作为一个字符串:

However, if you prefer to use a server-side POST, you may want to check the following method which submits an HTTP post and returns the response as a string:

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;
}

参数需要的形式来传递:名1 =值1&放大器; 2 =值2

这篇关于谷歌Checkout的HTTP POST与ASP.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:41
查看更多