无法读取未定义的 属性 'protocol':axios 反应

Cannot read property 'protocol' of undefined : axios react

const config = {
   headers: { "Content-Type": "application/octet-stream" }
}

let files = this.state.files
let promises = []
files.map((item ,index) => {
   promises.push(axios.put(this.props.deal.authURL[index], item, config))
})

我收到这个错误:

Uncaught (in promise) TypeError: Cannot read property 'protocol' of undefined

我的目标是将 Axios 调用的所有结果存储在 promises 数组中。然后用Promise.all()函数一次全部解析。无法弄清楚为什么会出现错误。

感谢任何形式的帮助。谢谢

this.props.deal.authURL[index] 返回未定义的 url,这就是随机错误的原因。

推荐的解决方案

如上文所述,当我们发送格式错误的请求或错误的方法或 body/header 中的任何错误时会抛出此错误。
但是,如果您已经检查了所有这些,并且它们都没有问题,但您仍然收到错误,那么很可能是您错误地处理了响应。
如何纠正?
console.log(response) 发送请求总是一个好主意,这样我们就知道如何处理响应。

今天下午我遇到了类似的问题。坐了一会儿,更正了所有 methods/request 链接之类的东西后,我仍然遇到错误,然后我意识到我错误地处理了响应。

所以,总是建议console.log回复。