Linux 命令行访问接口:curl 和 wget 指南
在 Linux 命令行访问接口,一般可以使用 curl 或者 wget 命令来发送 HTTP 请求,获取接口返回数据。
使用 curl 命令访问接口:
curl http://example.com/api/users
这个命令会发送一个 GET 请求到 'http://example.com/api/users' 地址,获取接口返回数据。
如果接口需要传递参数,可以在命令中使用 -d 参数:
curl -d 'username=admin&password=123456' http://example.com/api/login
这个命令会发送一个 POST 请求到 'http://example.com/api/login' 地址,传递 username 和 password 参数,获取接口返回数据。
使用 wget 命令访问接口:
wget http://example.com/api/users
这个命令会发送一个 GET 请求到 'http://example.com/api/users' 地址,获取接口返回数据。
如果接口需要传递参数,可以在命令中使用 --post-data 参数:
wget --post-data='username=admin&password=123456' http://example.com/api/login
这个命令会发送一个 POST 请求到 'http://example.com/api/login' 地址,传递 username 和 password 参数,获取接口返回数据。
原文地址: https://www.cveoy.top/t/topic/nAXU 著作权归作者所有。请勿转载和采集!