gpt4 book ai didi

node.js - 无法加载资源: the server responded with a status of 431 (Request Header Fields Too Large)

转载 作者:行者123 更新时间:2023-12-03 15:59:27 26 4
gpt4 key购买 nike

当我尝试使用 React 应用程序中的 NodeJS api(构建 MERN 堆栈应用程序)时,我收到了相关错误“无法加载资源:服务器响应状态为 431(请求 header 字段太大)”

postman 的 API 工作正常

const onSubmit=async(e)=>{
e.preventDefault()
if(password!==password2){
console.log('passwords dont match')
}else{
const newUser={
name:name,
email:email,
password:password
}
try {
const config={
headers:{
'Content-Type':'application/json'
}
}
const body=JSON.stringify(newUser)

//axios has been set up as proxy
//http://localhost:3000
//we dont need to add the above to url
const res =await axios.post('/api/users',body,config)
console.log(res.data)

} catch (error) {
console.error(error.response.data)
}
}
}

最佳答案

The HTTP 431 Request Header Fields Too Large response status code indicates that theserver refuses to process the request because the request’s HTTP headers are too long.The request may be resubmitted after reducing the size of the request headers.431 can be used when the total size of request headers is too large, or when a singleheader field is too large. To help those running into this error, indicate which of the > two is the problem in the response body — ideally, also include which headers are toolarge. This lets users attempt to fix the problem, such as by clearing their cookies.Servers will often produce this status if:The Referer URL is too longThere are too many Cookies sent in the request

就我而言,我发送了太多 cookie,因为 localhost:4200 被用作 3 个不同项目的域......解决方案(删除无用的 cookie)

希望这有帮助...

关于node.js - 无法加载资源: the server responded with a status of 431 (Request Header Fields Too Large),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58976846/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com