当前位置: 首页 > news >正文

微信小程序post请求

一、普通请求

wx.request({url: 'http://43.143.124.247:8282/sendEmail',method: 'POST',data: {user: that.data.currarr[0][that.data.mulu[0]] + that.data.currarr[1][that.data.mulu[1]] + that.data.sushe,pwd: '3101435196@qq.com'},header: {'Content-Type': 'application/x-www-form-urlencoded', // 设置请求头 Content-Type},success: res => {console.log(res);},fail: err => {console.log(err);}})

二、云开发请求

调用端

wx.cloud.callFunction({name: 'request_spider',data: {code: 'sendEmail',url: 'http://43.143.124.247:8282/sendEmail',data: {user: that.data.currarr[0][that.data.mulu[0]] + that.data.currarr[1][that.data.mulu[1]] + that.data.sushe,pwd: '3101435196@qq.com'}}}).then(res => {console.log('update-->res', res)}).catch(err => {console.log('update-->err', err)})

被调用端

// 云函数入口文件
const cloud = require('wx-server-sdk')cloud.init({env: cloud.DYNAMIC_CURRENT_ENV
}) // 使用当前云环境// var request = require('request-promise');
const rp = require('request-promise-native');
const querystring = require('querystring');
const axios = require('axios')exports.main = async (event, context) => {// 根据发起请求携带的不同参数进行不同的操作const code = event.codeconsole.log("event---------------->", event)if (code == 'sendEmail') {// 进行登录操作return sendEmail(event.url, event.data);}
};// 登录函数
async function sendEmail(url, data) {const formBody = querystring.stringify(data);try {const options = {method: 'POST',uri: url,body: formBody,// json: false, // 自动将请求体转为JSONheaders: {'Content-Type': 'application/x-www-form-urlencoded','Content-Length': Buffer.byteLength(formBody) // 设置内容长度}};const response = await rp(options);return response;} catch (error) {console.error(error);return error;}
}

http://www.lryc.cn/news/356024.html

相关文章:

  • frm一级4个1大神复习经验分享系列(二)
  • 理解磁盘分区与管理:U启、PE、DiskGenius、MBR与GUID
  • GPT-4o和GPT-4有什么区别?我们还需要付费开通GPT-4?
  • 《C++ Primer Plus》第十二章复习题和编程练习
  • 2024 年科技裁员综合清单
  • Linux系统编程学习笔记
  • vue3 excel 文件导出
  • 优雅的代码规范
  • JVM、JRE 和 JDK 的区别,及如何解决学习中可能会遇到的问题
  • 【开源】加油站管理系统 JAVA+Vue.js+SpringBoot+MySQL
  • 详解 Scala 的泛型
  • 【本周面试问题总结】
  • SaltStack
  • 【Rust日报】Rust 中的形式验证
  • vue3项目中新增修改时使用nextTick时遇到的问题
  • 算法训练 | 二叉树Part7 | 530.二叉搜索树的最小绝对差、501.二叉搜索树中的众数
  • C++面向对象程序设计 - 标准输出流
  • 警惕Mallox勒索病毒的最新变种hmallox,您需要知道的预防和恢复方法。
  • 2024年华为OD机试真题-火星文计算-C++-OD统一考试(C卷D卷)
  • 3.00001 postgres如何初始化系统参数?
  • C# 读取 CSV 文件的方法汇总
  • element+ 引入图标报错 Failed to resolve import “@element-plus/icons-vue“ from “
  • Github 2024-05-25 开源项目日报 Top10
  • VPN的详细理解
  • java后端轮播图的设计
  • upload-labs 21关解析
  • 常用汇编指令
  • LabVIEW软件需求分析文档内容和编写指南
  • spring cache(三)demo
  • Android 应用开发语言选择对比