I'm having some difficulty figuring out why im getting a null response in angular when i try to do a post to a httpservlet (java) in a WAS environment.
What im trying to do is call an api to login. I would like to receive the response headers, but im getting a null response, making it impossible to do anything with the response.
I tried to send my parameters as form data with the content-type application/x-www-form-urlencoded;charset=UTF-8 and as query parameters with no content-type defined.
In both situations im able to login and im getting a 200 response with header information in my browser.
this is my call
return this.http.post(this.contextRoot.getHost() + 'osa-kantoor-ws/api/auth/login?' + param1 + "&" + param2,null, this.httpOptions).map((res : Response) => {
localStorage.setItem('currentUser', JSON.stringify(username));
return res;
});
My header info now is
httpOptions = {
headers: new HttpHeaders({'Content-Type' : 'application/json', 'Accept': 'application/text'}),
params: {}
};
the localstorage item is set, but the response information is null.
this is my subscribe
login() {
this.loginService.login(this.loginForm.value.userName,this.loginForm.value.password)
.subscribe(
data => {
console.log(data);
this.router.navigate([this.returnUrl]);
},
error => {
console.log(error);
this.loginfail = true;
});
}
When im checking the browser info on my response header i get the following info
can anyone tell me what im missing?
below is the original method
login(username: string, password: string) {
let param1: string = encodeURIComponent('userName') + '=' + encodeURIComponent(username);
let param2: string = encodeURIComponent('password') + '=' + encodeURIComponent(password);
let formParams: string = param1 + '&' + param2;
return this.http.post(this.contextRoot.getHost() + 'osa-kantoor-ws/api/auth/login', formParams, this.httpOptions).map(response=> {
localStorage.setItem('currentUser', JSON.stringify(username));
console.log(response);
return response;
});
}
thank you AJT_82,
adding observe: 'response' to the config is the solution.
response is now what i expect. the default response is observe: 'body' apparently.
My HTTP config is now
httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8','Accept': 'application/xml'}),
observe: 'response'
};
and my response is now
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments