小程序
小游戏
企业微信
微信支付
扫描小程序码分享
下图为报错信息:
3 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
遇到同样的问题,一摸一样,请问解决了么
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
不知道行不行,试试吧
exports.main = async (event, context) => { var option = { headers: { 'Accept': '*/*', 'Accept-Encoding': 'utf-8', 'Accept-Language': 'zh-CN,zh;q=0.8', 'Connection': 'keep-alive', 'user-agent': 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Mobile Safari/537.36', } }; return await new Promise((resolve, reject) => { try { https.get(event.url, option, (res) => { var contont = '', location = res.headers.location res.on('data', (chunk) => { contont += chunk }); res.on('end', () => { resolve({location,contont}) }); }).on('error', (e) => { reject(e) }); } catch (e) { reject(e) } }) }
至少先调通一个最简单的云函数吧?然后再慢慢添加代码。
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
遇到同样的问题,一摸一样,请问解决了么
不知道行不行,试试吧
exports.main = async (event, context) => { var option = { headers: { 'Accept': '*/*', 'Accept-Encoding': 'utf-8', 'Accept-Language': 'zh-CN,zh;q=0.8', 'Connection': 'keep-alive', 'user-agent': 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Mobile Safari/537.36', } }; return await new Promise((resolve, reject) => { try { https.get(event.url, option, (res) => { var contont = '', location = res.headers.location res.on('data', (chunk) => { contont += chunk }); res.on('end', () => { resolve({location,contont}) }); }).on('error', (e) => { reject(e) }); } catch (e) { reject(e) } }) }
至少先调通一个最简单的云函数吧?然后再慢慢添加代码。
const cloud = require('wx-server-sdk')
const https = require('https');
cloud.init()
// 云函数入口函数
exports.main = async (event, context) => {
var option = {
headers: {
'Accept': '*/*',
'Accept-Encoding': 'utf-8',
'Accept-Language': 'zh-CN,zh;q=0.8',
'Connection': 'keep-alive',
'user-agent': 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Mobile Safari/537.36',
}
};
await new Promise((resolve, reject) => {
try {
https.get(event.url,option, (res) => {
return resolve(res.headers.location)
})
} catch (e) {
return reject(e)
}
})
}