ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 在云函数中通过http请求第三方服务 * [ ] 云函数中的请求不受小程序域名限制 * [ ] 云函数支持更多样化的请求方式 >示例代码 ```JavaScript // 云函数入口文件 const cloud = require('wx-server-sdk') const got = require('got') exports.main = async (event, context) => { try{ const response = await got("https://wechat.com"); console.log(response.body) } catch(e){ console.log(e.response.body) } } ``` * 放置一个按钮 ![](https://img.kancloud.cn/1e/2b/1e2b49e44a62b0f58a56eb95c4e08da2_1178x199.png) * 创建所需云函数 ![](https://img.kancloud.cn/d1/f5/d1f5d1ecc107f80b86d38ec9a6e9c721_307x510.png) * 安装got,在所用云函数文件夹点右键>在终端打开>输入下面代码等待安装 `npm i got` * 云函数代码 ```javascript // 云函数入口文件 const cloud = require('wx-server-sdk') const got = require('got') cloud.init() // 云函数入口函数 exports.main = async (event, context) => { let response = await got("https://wechat.com"); return response.body } ```