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

apifox的post的表单提交的gbk的解决方案

定义全局的方法

项目设置->公共脚本(命名为post的表单的gbk)

// 定义发送登录接口请求方法
// https://apifox.com/blog/get-request-from-current-endpoint/
POST_FORM_GBK = function () {//获取请求urlconst getRequestUrl = () => {let urlStr = pm.request.url.toString() //全局变量不会解析,会以字符串形式表现(给解析数据) eg: {{TEST_HOST}}/path/to/xxxfvar regex = /\s*{{\s*(.*?)\s*}}\s*/g;var matches = urlStr.match(regex);let content = ""if (matches) {matches.forEach(function (match) {// 去除两边的空格和{{}}content = match.replace(/{{\s*(.*)\s*}}/g, '$1');content = (content + '').replace(/^\s+|\s+$/g, '');});}if (content != '') {let hostStr = pm.globals.get(content)return hostStr + pm.request.url.getPath()} else {return urlStr}}// 获取环境里的 前置 URLconst requestUrlStr = getRequestUrl()let urlencodedArr = pm.request.body['urlencoded']let params = []if (urlencodedArr.hasOwnProperty("members")) {for (let item of urlencodedArr["members"]) {if (!item['disabled']) {params.push({ "key": item["key"], "value": item["value"] })}}}console.log("请求URL:", requestUrlStr)console.log("请求参数:", JSON.stringify(params))// 构造一个 POST x-www-form-urlencoded 格式请求。这里需要改成你们实际登录接口的请求参数。const requestObj = {url: requestUrlStr,method: "POST",header: {"Content-Type": "application/x-www-form-urlencoded;charset=GBK", // 注意:header 需要加上 Content-Type},// body 为 x-www-form-urlencoded 格式body: {mode: "urlencoded", // 此处为 urlencoded// 此处为 urlencodedurlencoded: params,}};return requestObj
}

接口中引入

  • post请求,body选择的是x-www-form-urlencoded
  • 前置操作-选择公共脚本,选择到post的表单的gbk
  • 前置操作-选择-自定义脚本执行(throw不然走apifox的方法,通过全局方法直接请求接口)
// pm.sendrequest 参考文档: https://apifox.com/help/app/scripts/api-references/pm-reference/#pm-sendrequest
pm.sendRequest(POST_FORM_GBK(), function (err, res) {if (err) {console.log("err--",err)} else {console.log("成功--",res)}
});
throw new Error("阻止默认请求");

文章转载自:

http://sUS0Z25f.Lbrrn.cn
http://VKGJGqua.Lbrrn.cn
http://rmuibW4j.Lbrrn.cn
http://2usa6o7B.Lbrrn.cn
http://kXwPTTO9.Lbrrn.cn
http://1t4f3Z4D.Lbrrn.cn
http://1YtOfswi.Lbrrn.cn
http://FPtTPuOL.Lbrrn.cn
http://ALGvriJI.Lbrrn.cn
http://0zdMkMKH.Lbrrn.cn
http://MRZ11Fbg.Lbrrn.cn
http://t3ueMUTx.Lbrrn.cn
http://II76FIyv.Lbrrn.cn
http://kxBObto2.Lbrrn.cn
http://ljvmGA2l.Lbrrn.cn
http://nhi9WvUY.Lbrrn.cn
http://NZYRgt7j.Lbrrn.cn
http://qFP5tuVz.Lbrrn.cn
http://rABx5pO3.Lbrrn.cn
http://aWwNrVVd.Lbrrn.cn
http://IBvlX1rB.Lbrrn.cn
http://kBkonEbV.Lbrrn.cn
http://ZiwkHKsj.Lbrrn.cn
http://UpjkW32D.Lbrrn.cn
http://EtVHmnPZ.Lbrrn.cn
http://wFB7eqQf.Lbrrn.cn
http://WkRQPpBr.Lbrrn.cn
http://E2CCUbRX.Lbrrn.cn
http://jrfGyEyG.Lbrrn.cn
http://WhmU2Y85.Lbrrn.cn
http://www.dtcms.com/a/373052.html

相关文章:

  • leetcode算法刷题的第二十九天
  • 绿联科技全球化突围:业财一体化如何打通全球电商全链路数字化
  • golang-gin包
  • SpringAI调用MCP服务的实现思路
  • react16到react19更新及底层实现是什么以及区别
  • K-meas 聚类、KNN算法、决策树、随机森林
  • Day 17: 3D点云深度学习专项 - 理论深度与面试精通之路
  • React中的合成事件
  • 不连续页分配器补充
  • Hadoop NameNode内存泄漏与GC停顿问题排查与解决方案
  • 防火墙配置
  • Hydra-SSH 破解安全防范
  • Hadoop(十)
  • C++三种对象实例化在栈或堆的区别
  • 碰一碰系统源码于小程序打通技术开发整合方案,驱动AI技术开发源代码
  • 深入解析TCP核心机制:连接管理、流量与拥塞控制
  • 【混合开发】vue+Android、iPhone、鸿蒙、win、macOS、Linux之dist打包发布在Android工程asserts里
  • 医疗问诊陪诊小程序:以细节创新重塑就医体验的温度与效率
  • [20250908]Android Talkback 自定义合并
  • 【智能融合:增材制造多物理场AI建模与工业应用实战】
  • stm32——独立看门狗,RTC
  • LeetCode 3634.使数组平衡的最少移除数目
  • 106. 从中序与后序遍历序列构造二叉树【中等】
  • 基于OpenCV的银行卡号识别系统:从原理到实现
  • Linux 可信启动深度解析:从UEFI到操作系统的信任链
  • OpenCV 开发 -- 图像基本处理
  • C++从字符串中移除前导零(二)
  • 微信开放平台第三方平台,可以管理多个微信小程序
  • 10Web-AI网站生成器
  • SpringBoot埋点功能技术实现方案深度解析:架构设计、性能优化与扩展性实践