如何从命令行使用 JSON 有效负载进行 HTTP 请求/调用? [英] How to do HTTP-request/call with JSON payload from command-line?

查看:28
本文介绍了如何从命令行使用 JSON 有效负载进行 HTTP 请求/调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从命令行进行 JSON 调用的最简单方法是什么?我有一个网站,它执行 JSON 调用以检索其他数据.

What's the easiest way to do a JSON call from the command-line? I have a website that does a JSON call to retrieve additional data.

Google Chrome 中显示的 Request Payload 如下所示:

The Request Payload as shown in Google Chrome looks like this:

{"version": "1.1", "method":"progr","id":2,"params":{"call":...} }

这是关于从(最好)linux 命令行进行调用并检索 JSON 内容,而不是解析传入的 JSON 数据.

It's about doing the call from (preferably) linux command line and retrieving the JSON content, not about parsing the incoming JSON data.

推荐答案

使用 curl,假设数据是 POST'ed,类似

Use curl, assuming the data is POST'ed, something like

curl -X POST http://example.com/some/path -d '{"version": "1.1", "method":"progr","id":2,"params":{"call":...} }'

如果您只是使用 GET 检索数据,并且不需要发送任何栏 URL 参数,你只需运行 curl http://example.com/some/path

If you're just retrieving the data with a GET , and don't need to send anything bar URL parameters, you'd just run curl http://example.com/some/path

这篇关于如何从命令行使用 JSON 有效负载进行 HTTP 请求/调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆