fetch post方式提交formdata数据报错

问题描述

我在使用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中

https://img.mukewang.com/5c8bc5640001286105910563.jpghttps://img1.mukewang.com/5c8bc54e0001be2306010561.jpg

结构在浏览器中不知道为什么报错
https://img.mukewang.com/5c8bc58100019c6108450726.jpg

求教……


小怪兽爱吃肉
浏览 3132回答 2
2回答

宝慕林4294392

  headers: {    "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"   },
打开App,查看更多内容
随时随地看视频慕课网APP