1

我正在查看 PayPal Curl 调用的文档……其中一部分如下所示:

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"

我正在尝试编写要在 Android 应用程序中实现的贝宝交互,并且我正在使用 Apache Commons,并且不清楚这些开关(特别是-u)如何映射到我创建的请求。

我猜这-H只是标准标题。并且-d是发布/获取查询参数数据...但是我该怎么办-u

就此而言,在哪里可以找到此处列出的开关http://curl.haxx.se/docs/manpage.html与手动 HTTP 请求中的等效开关之间的相关性?

4

2 回答 2

2

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.

于 2013-10-20T03:31:48.783 回答
2

-u, --user选项似乎提供了用户身份验证信息,所以我猜 PayPal 正在使用 HTTP 身份验证?如果是这样,下面的帖子会有所帮助。

使用 HttpClient 在 Java 中进行 Http 基本身份验证?

于 2013-10-20T03:23:21.517 回答