Curl PUT Request With JWT Authorization Header

3,544 views
Skip to first unread message

bit.io.c...@gmail.com

unread,
Aug 22, 2016, 5:44:50 PM8/22/16
to Django REST framework

I am still getting a hang of using curl for testing API request from the terminal. I have a particular issue with formatting because the API request I am attempting requires a JWT Token to be passed with every call. The request I am attempting to pass is PUT request and my question is where to place the header for the JWT token authorization. I have tried the following format and I get a error Could not resolve host: —H curl: (6) Could not resolve host: Authorization:


curl -X PUT -H "Authorization: JWT <token here>" -d "field=value" "https://url/update_record/<id>/"
 

Any ideas?

Andrew Backer

unread,
Aug 22, 2016, 11:26:20 PM8/22/16
to django-res...@googlegroups.com
Try using the `httpie` utility, you'll find it _much_ less of a pain in the ass than `curl`.  Gave up on that ages ago.

```
pip install httpie
export TOKEN=`get token value`
http put url.com/route/ field=value Authorization:"JWT $TOKEN"
```

As for the Curl line, it looks fine to me, i don't see anything obviously wrong.  is the "-" in "-H" the right dash?


August 23, 2016 at 5:44 AM

I am still getting a hang of using curl for testing API request from the terminal. I have a particular issue with formatting because the API request I am attempting requires a JWT Token to be passed with every call. The request I am attempting to pass is PUT request and my question is where to place the header for the JWT token authorization. I have tried the following format and I get a error Could not resolve host: —H curl: (6) Could not resolve host: Authorization:


curl -X PUT -H "Authorization: JWT <token here>" -d "field=value" "https://url/update_record/<id>/"
 

Any ideas?

--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Peter Boyles

unread,
Aug 23, 2016, 9:19:22 AM8/23/16
to Django REST framework
Hi Andrew,

I tried that call and got this strange message:

HTTP/1.1 500 INTERNAL SERVER ERROR
Connection: keep-alive
Content-Type: text/html
Date: Tue, 23 Aug 2016 13:15:20 GMT
Server: gunicorn/19.6.0
Transfer-Encoding: chunked
Vary: Cookie
Via: 1.1 vegur
X
-Frame-Options: SAMEORIGIN


http
: error: ChunkedEncodingError: ('Connection broken: IncompleteRead(2785 bytes read, 7455 more expected)', IncompleteRead(2785 bytes read, 7455 more expected))

Enter code here...
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+unsub...@googlegroups.com.

voger

unread,
Aug 23, 2016, 2:06:53 PM8/23/16
to django-res...@googlegroups.com
Personally I prefer "postman rest client". Much less trouble bout since
you insist going CLI here is the notes file from
codingforentrepreneurs.com course on django Rest Framework.

They have it open in github and I think this particular line might
interest you.

https://github.com/codingforentrepreneurs/srvup-rest-framework/blob/master/src/srvup/api_curl_tests.py#L30
> --
> You received this message because you are subscribed to the Google
> Groups "Django REST framework" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-rest-fram...@googlegroups.com
> <mailto:django-rest-fram...@googlegroups.com>.

voger

unread,
Aug 23, 2016, 2:25:24 PM8/23/16
to django-res...@googlegroups.com
BTW the error you get it doesn't have to do with the authorization.
It says that it can't resolve the url.

Is the url you posted the actual url that you are trying? It doesn't
seem right.
Reply all
Reply to author
Forward
0 new messages