4

I'm having trouble finding much details on this. I need to work with an api that processes credit cards and it uses curl. All documentation is in php and while I could use php my main site is entirely in MVC4 using razor view engine. I need to convert this wich is from php to something useable in .net

$ curl https://api.stripe.com/v1/customers -u *private key here*: 
       -d "description=Customer for [email protected]" -d "card[number]=4242424242424242" 
       -d "card[exp_month]=12" -d "card[exp_year]=2013"

Thanks in advance for your time

2
  • you can use the System.Web.WebClient object to perform that Commented Dec 23, 2012 at 21:56
  • What do the -u and -d options do? Are they just query string / post data? Commented Dec 23, 2012 at 22:02

1 Answer 1

5

from the curl manual page

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

so you can "decode" this as:

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

updated with POST tweak from an existing answer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.