云函数request访问http超时,但是本地调试却可以,有没有办法解决?
发布于 6 年前 作者 jie37 15076 次浏览 来自 官方Issues

如题,在网上看到说云函数可以使微信小程序访问http,试了后也只有在本地调试的时候才可以成功访问到,关了或者在真机上都不能实现,该怎么办?

2 回复
本地代码
wx.cloud.callFunction({
   name: 'Login',
   data: {
      URL: 'http://xxxxxxx.com',
      headers: {
         'Content-Type': 'application/x-www-form-urlencoded',
         'Accept-Encoding': 'gzip, deflate',
         'Accept-Language': 'en-us',
         'Accept': 'text / html, application/xhtml+xml,application/xml; q=0.9, image/webp,image/apng, */*;q=0.8,application/signed-exchange;v=b3;q=0.9',
         'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36',
         },
         methor: 'GET'
         }
     }).then(res => {
         console.log(res)
      })

//----------------------------
云函数代码
exports.main = async (event, context) => {
   return await request({
      url: event.URL,
      method: event.methor,
      json: true,
      headers: event.headers,
      qs: event.data_,
   }).then(res => {
      if(res.result.statusCode == 200){
         if (res.result.data.find('账号密码验证失败')){
            return 'id or pas wrong'
         }else{
            return res
         }
      } else if (res.result.statusCode == 302)
          return res
      else 
           return res
      }).catch(res => {
          return res
      })
}

能先亮代码,大佬

回到顶部