During the process of converting my AngularJS project into Angular 4, I encountered an issue with maintaining the Http connection after logging into the application.
The request I am making is:
POST /myapp-services/login.html?username=admin&password=admin
After submitting the login form in both versions of Angular, I receive a response code of 202. The main difference I noticed is related to the Connection
header. In AngularJS, there is no connection: close
, but in Angular 4, this header is present. The problem arises in Angular 4 where I am unable to proceed with subsequent requests as it keeps redirecting me back to login.html repeatedly. My goal is to authenticate the user before sending any requests to the server. What could be causing this issue?
In Angular 4, I have configured proxy.config as follows:
{
"/myapp-services":{
"target":"https://localhost:8443/",
"secure":false,
"loglevel":"debug"
}
}
Below are the comparison of response and request headers in both versions.
AngularJS:
General:
Request URL: https://localhost:8443/myapp-services/login.html?username=admin&password=admin
Request Method: POST
Status Code: 200 OK
Remote Address: [::1]:8443
Referrer Policy: no-referrer-when-downgrade
Response Headers:
Access-Control-Allow-Headers: x-requested-with, Content-Type
Access-Control-Allow-Methods: POST, GET, PUT, OPTIONS, DELETE
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Length: 0
Date: Tue, 10 Jul 2018 08:27:03 GMT
Expires: 0
Pragma: no-cache
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=9A05186F8DF53656747EDFA7567E7A4E; Path=/myapp-services; Secure; HttpOnly
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
Request Headers:
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,hi;q=0.8,es;q=0.7
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 0
Cookie: JSESSIONID=07CB8F42CB8B582768E0813C18AA733F
Host: localhost:8443
Origin: https://localhost:8443
Pragma: no-cache
Referer: https://localhost:8443/myapp-services/login.html
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
Angular 4:
General:
Request URL: http://localhost:4200/myapp-services/login.html?username=admin&password=admin
Request Method: POST
Status Code: 200 OK
Remote Address: 127.0.0.1:4200
Referrer Policy: no-referrer-when-downgrade
Response Headers:
access-control-allow-headers: x-requested-with, Content-Type
access-control-allow-methods: POST, GET, PUT, OPTIONS, DELETE
access-control-allow-origin: *
access-control-max-age: 3600
cache-control: no-cache, no-store, max-age=0, must-revalidate
connection: close
content-length: 0
date: Tue, 10 Jul 2018 08:30:04 GMT
expires: 0
pragma: no-cache
server: Apache-Coyote/1.1
set-cookie: JSESSIONID=02F1318A13C4A08CA3A0D4E9E1816E5A; Path=/myapp-services; Secure; HttpOnly
strict-transport-security: max-age=31536000 ; includeSubDomains
x-content-type-options: nosniff
x-frame-options: DENY
X-Powered-By: Express
x-xss-protection: 1; mode=block
Request Headers:
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,hi;q=0.8,es;q=0.7
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 0
Content-Type: application/json
Host: localhost:4200
Origin: http://localhost:4200
Pragma: no-cache
Referer: http://localhost:4200/login
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
X-Requested-With: XMLHttpRequest