macOS下测试json post rest api的方法

最近经常需要开发Web API,其中JSON格式的POST请求最为常见。由于普通的浏览器无法直接测试,所以需要借助命令行或者其他工具。

除了可以使用curl加参数的方法进行测试,在macOS的开发环境下,推荐使用图形化界面Cocoa Rest Client

方法一、使用CURL命令行

curl的使用手册

使用curl请求post,参数为json数据。例如:

curl -H "Accept: application/json" \
     -H "Content-type: application/json" \
     -v -X POST -d \
     '{"api_action": "auth","data": {"name" : "test", "sn" : "xxxxxx"}}' \
     https://api.mydomian.com/api/v1/myapi

方法二、Cocoa Rest Client图形化工具

作者网站:http://mmattozzi.github.io/cocoa-rest-client/

Share Comments
comments powered by Disqus