curl工具post用法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了curl工具post用法相关的知识,希望对你有一定的参考价值。

1.curl usage

For sending data with POST and PUT requests, these are common curl options:

  • request type

     -X POST

     -X PUT

  • content type header

     -H "Content-Type: application/x-www-form-urlencoded"

     -H "Content-Type: application/json"

  • data

     form urlencoded: -d "param1=value1&param2=value2" or -d @data.txt

     json: -d '{"key1":"value1", "key2":"value2"}' or -d @data.json


2. example

2.1 post urlencode binary data

curl -X POST --data-binary $'some_metric{label="val1"} 42
' "
 

cat <<EOF | curl --data-binary @- http://pushgateway:9091/metrics/job/some_job/instance/some_instance
TYPE some_metric counter
some_metric{label="val1"} 42
TYPE another_metric gauge
HELP another_metric Just an example.
another_metric 2398.283
EOF

curl -d "param1=value1&param2=value2" -H "Content-Type: application/x-www-form-urlencoded" -X POST  
curl -d "@data.txt" -X POST http://localhost:3000/data

2.2 post json data

curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST 
 
curl -d "@data.json" -X POST http://localhost:3000/data



以上是关于curl工具post用法的主要内容,如果未能解决你的问题,请参考以下文章

文档中除了 CURL Post 示例之外的 Solace Rest API 用法或示例

curl命令用法

php实现模拟post请求用法实例

curl命令的用法

curl命令常用用法

PHP的curl功能扩展基本用法