-d和-u参数的含义(以及提供的方法)是什么?

时间:2019-09-02 18:23:56

标签: json scala rest paypal playframework

我正在尝试使用Scala中的Playframework进行WS GET调用,以调用Paypal REST JSON API。我更具体地尝试get the initial Paypal access token

http://localhost:3000

我这样做是在Scala中构建的:

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

我在这里假设原始@Inject(ws: WSClient) val url = config.get[String]("paypal.url.token") // https://api.sandbox.paypal.com/v1/oauth2/token val httpHeaders = Array( "Accept" -> "application/json", "Accept-Language" -> "en_US" ) val username = config.get[String]("paypal.client_id") val password = config.get[String]("paypal.secret") val request: WSRequest = ws.url(url).withHttpHeaders(httpHeaders: _*). withRequestTimeout(timeout). withAuth(username, password, WSAuthScheme.BASIC) val futureResponse = request.get() futureResponse.map { response => println(response.json) } 中的-u意味着并对应于curl,但是我不知道withAuth的{​​{1}}对应什么来吗?

当我像现在这样运行时,出现以下错误: -d

和一些在日志之前的时间: grant_type=client_credentials

2 个答案:

答案 0 :(得分:2)

您可以使用curl阅读man curl手册。

所以, 1)-u代表--user <username:passsword>

   -u, --user <user:password>
          Specify the user name and password to use for server authentication. Overrides -n, --netrc and --netrc-optional.

          If you simply specify the user name, curl will prompt for a password.

这也可以翻译为-H "Authorization: <Basic|Bearer> base64_for_username:password"

2)-d代表POST请求中的--data或有效负载。

   -d, --data <data>
          (HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has
          filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the  con-
          tent-type application/x-www-form-urlencoded.  Compare to -F, --form.

答案 1 :(得分:1)

尝试使用post而不是像这样的get

ws
  .url(url)
  .withAuth(username, password, WSAuthScheme.BASIC)
  .post(Map("grant_type" -> Seq("client_credentials")))
  .map(println)