Question

I'm looking at the documentation for the PayPal Curl call... a part of it looks like this:

curl https://api.sandbox.paypal.com/v1/oauth2/token \
 -H "Accept: application/json" \
 -H "Accept-Language: en_US" \
 -u "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp:EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp" \
 -d "grant_type=client_credentials"

I'm trying to write a paypal interaction to be implemented in an Android app and I'm using Apache Commons and am unclear about how these switches (specifically the -u) map to the request I create.

I'm guessing that -H are just standard headers. and -d is the post/get query param data... but what do I do with -u

For that matter, where does one look for the correlation between the switches listed here http://curl.haxx.se/docs/manpage.html and their equivalent in a manual HTTP request?

Was it helpful?

Solution

There's no need to guess at the meaning of the options for curl, since you already know where the manpage is. You are of course correct in your interpretation of -d (request body) and -H (headers). And -u is on the man page as supplying the user and password.

I'm not aware that anyone has created a mapping of all curl options to their effect on building an HTTP request. Many are obvious, though, from the descriptions on the manpage. Some, like -i affect how curl shows it output so they have no effect.

In the case of -u if you really want to know what this does to your request, you can see the Wikipedia page on HTTP Basic Authentication to see what the auth header looks like (it uses Base64 encoding and is interesting in its own right). Programmers needn't bother with the Base64 encoding so clients, like curl, give you a way to specify auth values in a user-convenient manner.

Ultimately your request will have an initial line with the method, path, and version, then a bunch of headers, and then a body. How curl creates the request would best be found in the curl source code, perhaps (only slightly kidding here), but you can learn a lot by experimentation. Fire off some requests with curl using the -v (verbose) option! Look at the lines starting with > and you will see your request! This is a very nice way to learn both curl and HTTP in general.

OTHER TIPS

The -u, --user option seems provide user authentication information, so I guess PayPal is using HTTP Authentication? If so, the below post will help.

Http Basic Authentication in Java using HttpClient?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top