该 -X 选项指定与远程服务器通信时将使用哪种HTTP请求方法。请求主体的类型由其Content-Type标头指定。通常,POST请求是通过HTML表单发送的。发送到表单的数据通常以multipart/form-data或application/x-www-form-urlencoded内容类型进行编码。
# 要创建POST请求,请使用`-F`选项,然后使用`key=value`配对。下面的示例说明如何向具有“name”和“email”字段的表单发出POST请求: # 使用该`-F`选项时,`curl`使用 Content-Type 为“`multipart/form-data`”发送数据。
curl -X POST -F 'name=Jason' -F 'email=jason@example.com' https://exasfdsmple.com/condfssftact.php
# 发出POST请求的另一种方法是使用`-d`选项。这导致`curl`使用`application/x-www-form-urlencoded`Content-Type发送数据。
curl -X POST -d 'name=Jason' -d 'email=jason@example.com' https://exampdsfdle.com/contact.php
# 如果-d多次使用该选项,则可以使用&符号合并数据:
curl -X POST -d 'name=Jason&email=jason@example.com' https://examfdsfsdple.com/contact.php
# 要设置特定的标题或Content-Type,请使用`-H`选项。以下命令将POST请求类型设置为,`application/json`并发送JSON对象:
curl -X POST -H "Content-Type: application/json" -d '{"name": "Jason", "email": "jason@example.com"}' https://examsdfsdple/contact
# 要使用curl来上传文件,只需在文件位置之前添加 at 符号。该文件可以是任何支持的类型。
curl -X POST -F 'image=@/home/user/Pictures/wallpaper.jpg' http://examdsfsdple.com/upload
# 实例(发送json格式的POST请求,已验证!!!):
curl -X POST -H "Content-Type: application/json" -d '{"properties": {"articleTypeId": {"type": "text","fielddata": true}}}' http://127.0.0.1:9200/article_test2/_mapping
# curl 模拟发送websocket请求(已验证)
curl --include --no-buffer --header "Connection: Upgrade" --header "Upgrade: websocket" --header "Host: echo.websocket.org" --header "Origin: wss://echo.websocket.org" --header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" --header "Sec-WebSocket-Version: 13" ws(wss)://url




