如何为POST请求创建CURL命令 - {“error”:“invalid_scope”,“error_description”:“空范围(不允许客户端或用户)

时间:2016-08-16 18:58:04

标签: curl

我是 CURL 命令的新手。我能够从Mozilla REST客户端成功获取以下URL的响应:

http://localhost:8080/demo.rest.springsecurity.oauth2.0.authentication/oauth/token?username=user1&password=user1&client_id=client1&client_secret=client1&grant_type
=password&scope=read,write,trust

enter image description here

但是当我使用CURL命令尝试相同时,我看到错误。我创建了如下的CURL命令。请告诉我这里需要纠正的内容。

curl -X POST http://localhost:8080/demo.rest.springsecurity.oauth2.0.authentication/oauth/token -H “Accept: application/json” -d 
"username=user1&password=user1&client_id=client1&client_secret=client1&grant_type=password"

这给我以下错误:

C:\>curl -X POST http://localhost:8080/demo.rest.springsecurity.oauth2.0.authentication/oauth/token -H "Accept: application/json" -d "username=user1&password=user1&client_id=client1&client_secret=client1&grant_type=password"
{"error":"invalid_scope","error_description":"Empty scope (either the client or the user is not allowed the requested scopes)"}curl: (6) Could not resolve host: application

修改 根据Yuvika的回复,我得到了

C:\>curl -vvv -X POST "http://localhost:8080/demo.rest.springsecurity.oauth2.0.authentication/oauth/token?username=user1&password=user1&client_id=client1&client_secret=client1&grant_type=password&scope=read,write,trust"
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /demo.rest.springsecurity.oauth2.0.authentication/oauth/token?username=user1&password=user1&client_id=client1&client_secret=client1&grant_type=password&scope=read,write,trust HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.46.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Cache-Control: no-store
< Pragma: no-cache
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Date: Wed, 17 Aug 2016 05:36:08 GMT
<
    {"access_token":"ed788e8c-e504-4307-b43e-558914f85bf3","token_type":"bearer","refresh_token":"3e7e7dca-0db3-4423-a49d-
842783fd9632","expires_in":299999,"scope":"read,write,trust"}* Connection #0 to host localhost left intact

1 个答案:

答案 0 :(得分:1)

如果您使用-d,则该参数将作为请求正文发送,而不是请求网址的一部分。你的应用程序支持这个吗?如果没有,这应该有效curl -vvv -X POST "http://localhost:8080/demo.rest.springsecurity.oauth2.0.authentication/oauth/token?username=user1&password=user1&client_id=client1&client_secret=client1&grant_type =password&scope=read,write,trust"