ASP.NET MVC Twist Equivalent

I am having trouble finding the details. I need to work with an api that processes credit cards and uses curl. All documentation is in php, and although I can use php, my main site is entirely in MVC4 using a razor viewer mechanism. I need to convert this from php to something useful in .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" 

Thank you in advance for your time.

+4
source share
1 answer

from curl manual page

  • -u, --user <user:password> - user credentials
  • -d, --data <data> - POST data

so you can "decode" it like:

 using (var wc = new System.Net.WebClient()) { // data string parameters = string.Concat("description=", description, "&amp;card[number]=" , cardNumber, "&amp;card[exp_month]=", cardExpirationMonth, "&amp;card[exp_year]=", cardExpirationYear), url = "https://api.stripe.com/v1/customers; // let 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); } 

updated by setting the POST from an existing response .

+5
source

All Articles