I think that you mix two different things. For what I saw in the code you provided, you want to send credentials from a form using an AJAX request using Angular2 HTTP
class. In this case, you need to provide this content within the second parameter of the post
method, as described below:
var creds = "username=" + username + "&password=" + password;
var headers = new Headers();
headers.append('Content-Type',
'application/x-www-form-urlencoded');
this.http.post(
'http://localhost/jiffy_fun/laravel/public/token',
creds,
{headers: headers})
.map(res => res.json())
.subscribe(res => {this.token = res});
The withCredentials
attribute is something different related to CORS (cross domain requests). In fact, by default, CORS doesn't send cookies for such requests. You can choose to change this behavior by setting the withCredentials
attribute to true
on the xhr object. This link could give you some additional hints: http://www.html5rocks.com/en/tutorials/cors/?redirect_from_locale=fr. See this withCredentials
section.
Hope it helps you,
Thierry