如何使用授权令牌向 api 发出 http 请求?
How to make a http request to an api using a token for authorization?
我必须通过向指定地址发送请求来获取令牌。我用了
$ curl $ curl -XPOST -H "Content-Type: application/json" -d '{ "client_id": "xxx", "client_secret": "11111111", "grant_type": "client_credentials", "scope": "public" }' "https://example.com/auth/token"
我拿到了令牌abcdefg12345
现在我必须使用该令牌向此 url 端点发出请求(包括如下所示的参数):
$ curl -XGET -H "Authorization: Bearer {access_token}" "https://example.com/api/vacations/search?country=us&locale=en-US&price=affortable"
我不太熟悉 api 请求,但我尝试对其进行研究,所以我想做的是:
http.get("https://example.com/api/vacations/search?country=us&locale=en-US&price=affortable"+"&token=abcdefg12345")
不幸的是,这不起作用,我明白了:"access token not authorized"
有人能帮忙吗?我也不太确定 Bearer 令牌是否与“常规”令牌有任何不同,并且请求必须不同?也不确定将参数留在 url 端点是否正确,或者我应该这样指定它们:
http.get("https://example.com/api/vacations/search?"+params+"&token=abcdefg12345", {params:country='us', price:affordable})
非常感谢!
你会用
$ curl -H "Authorization: Bearer abcdefg12345" "https://example.com/api/vacations/search?country=us&locale=en-US&price=affortable"
你试过吗?结果如何?
我必须通过向指定地址发送请求来获取令牌。我用了
$ curl $ curl -XPOST -H "Content-Type: application/json" -d '{ "client_id": "xxx", "client_secret": "11111111", "grant_type": "client_credentials", "scope": "public" }' "https://example.com/auth/token"
我拿到了令牌
abcdefg12345
现在我必须使用该令牌向此 url 端点发出请求(包括如下所示的参数):
$ curl -XGET -H "Authorization: Bearer {access_token}" "https://example.com/api/vacations/search?country=us&locale=en-US&price=affortable"
我不太熟悉 api 请求,但我尝试对其进行研究,所以我想做的是:
http.get("https://example.com/api/vacations/search?country=us&locale=en-US&price=affortable"+"&token=abcdefg12345")
不幸的是,这不起作用,我明白了:"access token not authorized" 有人能帮忙吗?我也不太确定 Bearer 令牌是否与“常规”令牌有任何不同,并且请求必须不同?也不确定将参数留在 url 端点是否正确,或者我应该这样指定它们:
http.get("https://example.com/api/vacations/search?"+params+"&token=abcdefg12345", {params:country='us', price:affordable})
非常感谢!
你会用
$ curl -H "Authorization: Bearer abcdefg12345" "https://example.com/api/vacations/search?country=us&locale=en-US&price=affortable"
你试过吗?结果如何?