如何在React-Redux应用程序中修复431请求标头字段太大 [英] How to fix 431 Request Header Fields Too Large in React-Redux app

查看:485
本文介绍了如何在React-Redux应用程序中修复431请求标头字段太大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Redux的youtube上完成MERN注册/登录身份验证教程.尝试将测试用户发布到Postman中的服务器时,我收到431标头请求的错误响应太大.

I'm working through a MERN sign up/login auth tutorial on youtube that uses Redux. When attempting to POST a test user to the server in Postman, I receive the 431 header request is too large error response.

我在某些地方阅读过,可以清除浏览器中的缓存/历史记录,因此我尝试了一下,但无济于事.我还向标题请求中添加了"Clear-Site-Data":"*"条目(除了"Content-Type":"application/json"之外)也没有用.

I've read in some places that clearing the cache/history in your browser works, so I've tried that to no avail. I've also added in a "Clear-Site-Data": "*" entry to the header request (in addition to "Content-Type": "application/json") which hasn't worked, either.

用于注册的客户端代码

  onSubmit = e => {
    e.preventDefault();
    const { name, email, password } = this.state;

    const newUser = {
      name,
      email,
      password
    };

    this.props.register(newUser);
  };

//redux actions
export const register = ({ name, email, password }) => dispatch => {

  const config = {
    headers: {
      "Content-Type": "application/json",
      "Clear-Site-Data": "*"
    }
  };

  // Request body
  const body = JSON.stringify({ name, email, password });

  axios
    .post('/api/users', body, config)
    .then(res =>
      dispatch({
        type: REGISTER_SUCCESS,
        payload: res.data
      })
    )
    .catch(err => {
      dispatch(
        returnErrors(err.response.data, err.response.status, 'REGISTER_FAIL')
      );
      dispatch({
        type: REGISTER_FAIL
      });
    });
};

用户注册应该向我连接的Mongo数据库发送名称,电子邮件和密码,但是,它使我停止运行,并且redux击中了我创建的REGISTER_FAIL类型,并返回431错误.任何帮助将不胜感激.谢谢!

The user sign up should be sending a name, email and password to my connected Mongo db, however, it halts me and redux hits the REGISTER_FAIL type I created returning the 431 error. Any help would be greatly appreciated. Thank you!

推荐答案

我在Angular应用程序中也遇到了同样的问题.花了很多时间后,我发现问题与Node JS有关.我们使用的是Node JS v12.x.x,在此版本中,max-http-header-size从80KB减少到8KB.我拥有的auth令牌大约为10KB.这就是为什么当我重新加载应用程序时,浏览器开始为某些文件显示"431请求标头字段太大"错误.我已经更新了Node JS v14.x.x,它再次开始工作,因为在v14.0.0中,max-http-header-size已增加到16KB.

I had faced the same issue in my Angular Application. After spending a lot of time, I had found out that the issue is related with Node JS. We were using Node JS v12.x.x, and in this version, max-http-header-size reduced to 8KB from 80KB. And the auth token which I had was of around 10KB. That's why, when I reload the app, browser starts giving '431 request header fields too large' error for some of the files. I had updated the Node JS v14.x.x and it starts working again because in v14.0.0, max-http-header-size has been increased to 16KB.

希望这会有所帮助.

这篇关于如何在React-Redux应用程序中修复431请求标头字段太大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆