大佬帮忙看看这段代码有什么问题吗?为什么总是报appid找不到?
var token = await request({
url: "https://api.weixin.qq.com/cgi-bin/stable_token",
method: "POST",
json: true,
form: {
grant_type: "client_credential",
appid: "wxa4f5a91xxxx6f5",
secret: "d83eb0344cxxxxcbfa9aa917e03e"
},
headers: {
"content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
},
})
{
"errcode": 41002,
"errmsg": "appid missing rid: 65107638-2348b85b-0a154fd2"
}
发送JSON 数据。不是数组参数。
你在小程序端调用小程序的api?
Content-Type是application/json,不是 application/x-www-form-urlencoded
const request = require("request"); /** * 发起网络请求简易封装函数 * @param {object} url 请求接口 * @param {object} method 请求方式 * @param {object} paramObj 请求的参数对象 */ const requestFun = (url, method, paramObj = {}) => { // 请求数据 const options = { timeout : 5000, // 设置超时 method : method, //请求方式 url : url, headers : { "Content-Type" : "application/json", }, body : paramObj, json : true, }; // 发起请求 return new Promise((resolve, reject) => { request(options, function(error, response) { if (error) reject(error); resolve(response.body); }); }); };
curl命令可以正常访问,应该是代码哪里有问题,新手上路,大佬们请指教!
const got = require('got')
const resultValue_options = {
method: 'POST',
url: "https://api.weixin.qq.com/cgi-bin/stable_token",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
grant_type: "client_credential",
appid: "wxa4f5a91e38beb6f5",
secret: "d83eb0344c7ce53816cbfa9aa917e03e"
}),
responseType: 'json'
};
console.log("buffer======1111");
var {body} = await got(resultValue_options)
console.log("buffer", body);