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

发布时间: 2018-04-13 10:02:28 作者: 大象笔记

昨天写了几个小程序的后台接口,各种 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
我是一名山东烟台的开发者,联系作者