Following this example.

When I send a command to the website as thus, it works and returns a token:

[idf@xxxx ~]$  curl -d "name=Ivan&email=idf@xxxcom&password=secret" -H "Content-Type: application/x-www-form-urlencoded" -X POST localhost:3002/api/auth/register 


[idf@xxxx ~]$ 

I am then supposed to use this token to GET some information about the user. I tried this:

[idf@xxx ~]$  curl -v -d "x-access-token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVhNzIwODlhNGZkZTViNzM5N2M1YjQ5YiIsImlhdCI6MTUxNzQyMjc0NiwiZXhwIjoxNTE3NTA5MTQ2fQ.7a5KPDvB-13KYrAfkBa_2-d3XKru1J1OkxWlofnxhFw" -H "Content-Type: application/x-www-form-urlencoded" -X GET localhost:3002/api/auth/me
* About to connect() to localhost port 3002 (#0)
*   Trying ::1...
* Connected to localhost (::1) port 3002 (#0)
> GET /api/auth/me HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:3002
> Accept: */*
> Content-Type: application/x-www-form-urlencoded
> Content-Length: 186
* upload completely sent off: 186 out of 186 bytes
< HTTP/1.1 403 Forbidden
< X-Powered-By: Express
< Content-Type: application/json; charset=utf-8
< Content-Length: 45
< ETag: W/"2d-vj/ohbytTg+R1uXxU34fCnv4o0o"
< Date: Wed, 31 Jan 2018 18:29:45 GMT
< Connection: keep-alive
* Connection #0 to host localhost left intact
[idf@xxxx ~]$ 

But it comes back with:

{"auth":false,"message":"No token provided."}

[idf@xxxx ~]$

I am almost certainly using curl incorrectly to pass a parameter to GET. What is the correct way to form the curl GET string?


HTTP GET request arguments are passed in the URL like this:


So, in your case, the Curl command line would be:

curl http://localhost:3002/api/auth/me?x-access-token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVhNzIwODlhNGZkZTViNzM5N2M1YjQ5YiIsImlhdCI6MTUxNzQyMjc0NiwiZXhwIjoxNTE3NTA5MTQ2fQ.7a5KPDvB-13KYrAfkBa_2-d3XKru1J1OkxWlofnxhFw

This should work assuming that the API is really supposed to work via GET requests and query arguments.

However, the x-access-token argument sounds more like an HTTP header, and then you would need to use this command line:

curl -H "x-access-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVhNzIwODlhNGZkZTViNzM5N2M1YjQ5YiIsImlhdCI6MTUxNzQyMjc0NiwiZXhwIjoxNTE3NTA5MTQ2fQ.7a5KPDvB-13KYrAfkBa_2-d3XKru1J1OkxWlofnxhFw" http://localhost:3002/api/auth/me
  • I'm curious, which one works? – Tero Kilkanen Feb 1 '18 at 23:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.