ASP.NET MVC curl等价物

ASP.NET MVC curl等价物,curl,asp.net-mvc-4,Curl,Asp.net Mvc 4,我很难找到这方面的很多细节。我需要使用一个处理信用卡的api,它使用curl。所有文档都是php,虽然我可以使用php,但我的主站点完全是使用razor视图引擎的MVC4。我需要将它从php转换成一些在.net中可用的东西 $ curl https://api.stripe.com/v1/customers -u *private key here*: -d "description=Customer for test@example.com" -d "card[number]=

我很难找到这方面的很多细节。我需要使用一个处理信用卡的api,它使用curl。所有文档都是php,虽然我可以使用php,但我的主站点完全是使用razor视图引擎的MVC4。我需要将它从php转换成一些在.net中可用的东西

$ curl https://api.stripe.com/v1/customers -u *private key here*: 
       -d "description=Customer for test@example.com" -d "card[number]=4242424242424242" 
       -d "card[exp_month]=12" -d "card[exp_year]=2013"
提前感谢您在本页抽出时间

  • -u,--user
    是用户凭据
  • -d,--data
    是POST数据
因此,您可以将其“解码”为:



使用。

中的后期调整更新您可以使用
System.Web.WebClient
对象执行该操作
-u
-d
选项的作用是什么?它们只是查询字符串/post数据吗?
using (var wc = new System.Net.WebClient())
{
    // data
    string parameters = string.Concat("description=", description, "&card[number]=" , cardNumber, "&card[exp_month]=", cardExpirationMonth, "&card[exp_year]=", cardExpirationYear),
           url = "https://api.stripe.com/v1/customers;

    // let's fake it and make it was a browser requesting the data
    wc.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

    // credentials
    wc.Credentials = new System.Net.NetworkCredential("*private key here*", "");

    // make it a POST instead of a GET
    wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";

    // send and get answer in a string
    string result = wc.UploadString(url, parameters);
}