简体   繁体   中英

Failed to load resource: the server responded with a status of 400 (Bad Request): on Angular + NodeJS

I have an Angular and NodeJS application with Express (v4.17.1). I expose a REST API like this:

app.get('/myRestApi', function (req, res) 
{
  console.log('here you are ... ');
  res.end('success!\n');
});

and the body of this API contains these parameters:

{"name":"Joe",
 "surname":"Soap",
 "coordinate":"ASNDNFNS;SDFGSDFGSDF;ASFRTGERG;SERFQEAWE"}

The issue is that when I receive the coordinate field larger than a certain amount (so a lot of these ASFRTGERG;SERFQEAWE ) I get the error on the browser (regardless the browser):

The server responded with a status of 400 (Bad Request). 

As I do not get the console.log('here you are... '); log I suppose NodeJS discards it returning 400. I'm pretty sure NodeJS returns this as on the browser I get:

HTTP/1.1 400 Bad Request
Access-Control-Allow-Origin: *
Content-Length: 0
Connection: keep-alive
X-Powered-By: Express
Strict-Transport-Security: max-age=31536000

****UPDATE****

I've set the DEBUG level on NodeJS and the request never get to the backend so the problem is in the Angular side I believe. At one point on the Angular side I do this:

window.location.href = this.url;   //this.url = /myRestApi

which navigates to the /myRestApi URL. I believe that window.location.href mechanism got a problem here as one field of the body of this request (see above) is too big then it crashes? ... or something that cause 400.

Suggestions?

I've found the issue and the problem was that the HTTP GET sent to the backend was too big. After a deeper analysis, I've seen that the cookie made a huge difference in my case.

I've fixed it by increasing the max HTTP header size:

node --max-http-header-size 21000 application.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM