从命令行执行JSON调用最简单的方法是什么?我有一个网站执行JSON调用以检索其他数据。
Google Chrome中显示的请求有效负载如下所示:
{"version": "1.1", "method":"progr","id":2,"params":{"call":...} }
它是关于从(最好)linux命令行进行调用并检索JSON内容,而不是解析传入的JSON数据。
答案 0 :(得分:40)
使用curl,假设数据是POST,类似
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
答案 1 :(得分:38)
您也可以使用wget:
wget -O- --post-data='{"some data to post..."}' \
--header='Content-Type:application/json' \
'http://www.example.com:9000/json'
答案 2 :(得分:3)
curl --request POST \
--url http://localhost:8099/someservice/services/boo \
--header 'authorization: Basic dkfhsdlepwmdseA==' \
--header 'cache-control: no-cache' \
--header 'content-type: application/json' \
--data '{"value": "24.127.1212.123"}'
答案 3 :(得分:0)
你看过curl了吗?它非常适合通过命令行促进HTTP GET / POST请求。
e.g。 (对于GET请求):
C:\WINDOWS>curl "http://search.twitter.com/search.json?q=twitterapi&result_type=
popular"
{"results":[{"from_user_id_str":"32316068","profile_image_url":"http://a2.twimg.
com/profile_images/351010682/twitblock_profile_normal.png","created_at":"Thu, 25
Nov 2010 14:37:46 +0000","from_user":"twitblockapp","id_str":"7805146834669569"
,"metadata":{"result_type":"popular","recent_retweets":10},"to_user_id":null,"te
xt":"blocking and reporting functions are currently failing. @TwitterAPI have be
en notified. http://j.mp/id5w3m","id":7805146834669569,"from_user_id":32316068,"
geo":null,"iso_language_code":"en","to_user_id_str":null,"source":"<a href=&q
uot;http://twitter.com" rel="nofollow">Tweetie for Mac</a&g
t;"}],"max_id":9607558079713280,"since_id":0,"refresh_url":"?since_id=9607558079
713280&q=twitterapi","results_per_page":15,"page":1,"completed_in":0.012698,"sin
ce_id_str":"0","max_id_str":"9607558079713280","query":"twitterapi"}
答案 4 :(得分:0)
您也可以将wget
与post-file
一起使用,我认为这很有用。
wget --post-file=[file] --header=Content-Type:application/json [URL]
您可以将内容保留在文件中,并且内容将作为post
数据发送。