云函数调用https请求。代码正常,但是就是报错404011?
发布于 4 年前 作者 zding 8513 次浏览 来自 问答

控制台的错误信息:

Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID , cloud function service error code -504002, error message Function not found [getPostDetail]; at cloud.callFunction api; 

小程序里调用云函数的代码:

// 调用云函数
   wx.cloud.callFunction({
     name: 'getPostDetail',
     data: {
       id: this.id
     },
     success: res => {
       
     },
     fail: err => {
       
     }
   })

云函数 index.js代码

// 云函数入口文件
const cloud = require('wx-server-sdk')
var rp = require('request-promise');
cloud.init()
 
// 云函数入口函数
exports.main = async (event, context) => {
  return await rp({
    method: 'POST',
    uri: 'https://xxxxxxxx',
    body: {
      id: event.id,
    },
    headers:{
      'cookie':'xxxxxx',
      'Content-Type': 'application/json',
    },
    json: true
  }).then(function (res) {
    return res
  })
    .catch(function (err) {
    });
}

云函数请求url https://xxxxxxxx 已在config.json里添加

{
  "permissions": {
    "openapi": [
      "https://xxxxxxxxx"
    ]
  }
}

1 回复

有await就不要then了;

let res = await rp(…)

回到顶部