为了账号安全,请及时绑定邮箱和手机立即绑定

fetch post方式提交formdata数据报错

fetch post方式提交formdata数据报错

PHP
小怪兽爱吃肉 2019-03-03 07:20:22
问题描述我在使用fetch api的时候 在postman下测试接口可以正常返回数据,但是我使用fetch时,接口的状态码就直接302了相关代码这是我的fetch相关代码import 'whatwg-fetch'post(url, formData, headers) {    return new Promise(function(resolve, reject) {       fetch(url, {        method: 'POST',        headers: headers,        body: formData,        mode: 'no-cors'       })         .then(response => {          if (response.ok) {            return response.json()           } else {             reject({ status: response.status })           }         })         .then(response => {           resolve(response)         })         .catch(err => {           reject({ status: -1 })         })     })   }在使用的时候我是这样写的request.post(path, qs.stringify(params), {    'Content-Type': 'application/x-www-form-urlencoded'   })在postman中结构在浏览器中不知道为什么报错求教……
查看完整描述

2 回答

?
宝慕林4294392

TA贡献2021条经验 获得超8个赞

  headers: {    "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
  },


查看完整回答
反对 回复 2019-03-15
  • 2 回答
  • 0 关注
  • 3131 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信