shell 中的 lwp-request:如何使用 body 发出 POST 请求?

发布于 2024-11-28 15:22:46 字数 301 浏览 6 评论 0原文

我使用简单的 shell 脚本来测试一些处理 POST 请求的 http 服务器。 通常它看起来像:

echo "param1=value1&param2=value2" | POST localhost/service

但现在我想在 POST body 中传递一些 json,这就是我完全错过的地方。

man POST 和 google 也没有多大帮助。

看来这要么非常简单,要么完全不可能。

感谢您的帮助。

I use simple shell script to test some http server that process POST requests.
Usually it looks like:

echo "param1=value1¶m2=value2" | POST localhost/service

But now I want to pass also some json in POST body and that's where I missing point completely.

man POST and google did't help much also.

Seems it must be either very simple or completely impossible.

Thanks for help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瑶笙 2024-12-05 15:22:46

要么我遗漏了一些东西,要么你应该做

$ echo -n '{"json":"data"}' | POST -c "application/json" 'http://localhost/service?param1=value1¶m2=value2'

如果你需要将这些参数不作为 GET 而是作为 POST 放置,然后查找多部分表单数据。

Either I'm missing something, or you should do

$ echo -n '{"json":"data"}' | POST -c "application/json" 'http://localhost/service?param1=value1¶m2=value2'

If you need to put those parameters not as GET, but as POST as well, then look up multipart form data.

迷路的信 2024-12-05 15:22:46

您可能需要使用 -c 传递内容类型:

POST -c application/json

You probably need to pass content type using -c:

POST -c application/json
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文