Vue给接口传x-www-form-urlencoded类型参数

Vue给接口传x-www-form-urlencoded类型参数

今天在前端调用后端接口的时候出现了很多问题,出现问题的原因是跟后端没有及时的去沟通,自己一个人参考swagger接口文档闷头苦干。结果接口一直报400XSS参数攻击异常,没办法跟后端对接后才成功调用接口。

如何给接口传x-www-form-urlencoded类型的参数呢???
参考一下代码:

1.导入相关依赖
//格式化时间
import dayjs from "dayjs";
//Axios的配置文件
import Axios from '@/network/axios';
import qs from 'qs';


2.相关代码和注释
 let params = {
            'orgID': 'root',
            'serCreateTime': dayjs(this.userForm.etime).format("YYYY-MM-DD hh:mm:ss"),
            'userInvalidTime': dayjs(this.userForm.ltime).format("YYYY-MM-DD hh:mm:ss"),
            'userIsSuperAdmin': 0,
            'userLoginName': this.userForm.name,
            'userPassword': this.userForm.credential,
            'userUsesMark': this.userForm.status,
            'roleID': '10002',
            'userInfo.userChName': this.userForm.alias,
            'userInfo.userEmail': this.userForm.telephone,
            'userInfo.userGender': this.userForm.gender,
            'userInfo.userIDCard': this.userForm.idcard,
            'userInfo.userMobile': this.userForm.mobile,
            'userID': this.userForm.name
          }
          Axios({
          	//请求方式(get、post、put、delete)
            method: 'post',
            //接口访问地址(http://ip:port/路径)
            url: `xxxxxx/xxxxxx/xxxxxx`,
            data: qs.stringify(params),
            //请求头
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
            },
          }).then(res => {
          //请求成功的响应结果,可以做更多处理
            console.log(res);
          });

本人亲测有效,记录每天的工作成果希望对你有帮助!!!加油

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值