如何用curl向接口发送post
请求?
使用curl进行POST请求的语法如下:
curl -X POST -H "Content-Type: application/json" -d '{"key1":"value1", "key2":"value2"}' http://example.com/api
其中:
-X POST:指定请求方法为POST-H "Content-Type: application/json":设置请求头Content-Type为application/json-d '{"key1":"value1", "key2":"value2"}':设置请求体为JSON格式的数据http://example.com/api:指定请求的URL
例如,向http://example.com/api发送一个JSON格式的POST请求,请求体为{"name":"John","age":30},可以使用以下命令:
curl -X POST -H "Content-Type: application/json" -d '{"name":"John","age":30}' http://example.com/api
原文地址: https://www.cveoy.top/t/topic/bd3e 著作权归作者所有。请勿转载和采集!