使用 curl 测试微信小程序后台接口

更新日期: 2018-04-13 阅读次数: 10564 分类: 微信小程序

昨天写了几个小程序的后台接口,各种 bug,不自测就是不行。。。

由于微信小程序接口,大多是需要带上登录态,用浏览器来模拟请求也不方便;而我又不喜欢 post man 这种插件。所以尝试用 curl 来模拟测试请求:

请求头中的 Authorization: Bearer 部分为小程序的登录态。

#!/bin/bash

set -e  # or use "set -o errexit" to quit on error.
set -x  # or use "set -o xtrace" to print the statement before you execute it.

curl 'https://www.sunzhongwei.com/api/test_api' \
        -H 'content-type: application/json' \
        -H 'Accept: application/json' \
        -H 'Cache-Control: no-cache' \
        -H 'Authorization: Bearer xxx' \
        --data @- << EOF
{
    "company_name": "test"
}
EOF

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式