Home > Net >  React Typescript (.NET 6.0), fetch problem with JavaScript (HTTP Err 431)
React Typescript (.NET 6.0), fetch problem with JavaScript (HTTP Err 431)

Time:12-13

The fetch call response with "You need to enable JavaScript to run this app.". If I add "proxy": "http://localhost:3000", in the package.json, the response is following: HTTP 431 Request Header Fields Too Large, but the fetch file size is just 160 Bytes long.

The content of React.Component is as follows:

export default class Test extends React.Component<any, State> {
    constructor(props: any) {
        super(props);

        fetch('api/Test/Select', {
            headers: { 'Content-Type': 'application/json' },
            method: 'GET',
        })
            .then(response => response.json())          
    }
}

The Connector method is as follows:

[HttpGet("Select")]
public IActionResult Select()
{
   try
   {
      return Ok();
   }
   catch (Exception ex)
   {
      return Conflict(ex);
   }
}

The package.json file contents are as follows:

{
  "name": "clientapp",
  "version": "0.1.0",
  "private": true,
  "proxy": "http://localhost:3000",
  "dependencies": {
    "@testing-library/jest-dom": "^5.15.1",
    "@testing-library/react": "^11.2.7",
    "@testing-library/user-event": "^12.8.3",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "4.0.3",
    "react-router-dom": "6.0.2",
    "web-vitals": "^1.1.2",
    "@types/react": "17.0.37",
    "@types/reactstrap": "8.7.2",
    "antd": "4.17.2"
  },
  "devDependencies": {
    "cross-env": "7.0.3",
    "typescript": "4.5.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

CodePudding user response:

Maybe .NET 6 has an Bug with the fetch, idk. I just downgraded the Project to .NET Core 3.1 and everything is woking fine.

  • Related