简体   繁体   中英

How do I call my Django REST API endpoint with CURL?

I want to call my Django REST Framework API using cURL, but it doesn't do anything.

My URL is like "https://MYURL/api/seedevents?secret=SECRET". In postman this works and returns a 201 Created HTTP response. If I call using CURL for example "curl -XGET 'https://MYURL/api/seedevents?secret=SECRET', then it doesn't do anything at all. I can see the request come in in the logs, but it just doesn't do anything.

Please can someone advise me what I can do?

I guess it's probably missing some headers.

A helpful tip is to extract the curl command from Postman, on the right side you will find a code symbol as the below screenshot, that will make the same request in different form, choose cURL and use the command (make sure to use data instead of data-raw in case you have a payload)

在此处输入图像描述

Also add -vvv after curl to debug the curl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM