Linux用wget/curl 发起post请求
warning:
这篇文章距离上次修改已过437天,其中的内容可能已经有所变动。
使用wget发起POST请求需要使用--post-data参数,而curl则使用-d或--data参数。以下是使用这两个工具发起POST请求的示例。
使用wget发起POST请求:
wget --post-data 'param1=value1¶m2=value2' http://example.com/resource使用curl发起POST请求:
curl -d 'param1=value1¶m2=value2' http://example.com/resource在这两个例子中,我们将参数param1和param2与对应的值value1和value2通过查询字符串格式发送到http://example.com/resource。
注意:如果你需要发送JSON数据,你可能需要使用--header参数来指定Content-Type为application/json,并使用--data-binary来发送JSON字符串。
使用wget发送JSON数据:
wget --header="Content-Type: application/json" --post-data='{"param1":"value1", "param2":"value2"}' http://example.com/resource使用curl发送JSON数据:
curl --header "Content-Type: application/json" -d '{"param1":"value1", "param2":"value2"}' http://example.com/resource以上命令会将JSON数据作为POST请求的主体发送到指定的URL。
评论已关闭