暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

curl命令发送post请求总结笔记

原创 Shyai 2022-11-09
6117

该 -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

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论