just start learning angular2
followed the heroes
tutorial. I am making a create request, the URL is perfectly fine, the parameters are fine. But I am still confused why http://localhost:4200/
is being appended with my API
call, and because of that the URL gets totally changed, and the calls failed.please shed some light over this issue. I googled a lot but could find the reason.
My Create Method
create(user: object): Promise<any> {
return this.http
.post('localhost/usmanProject/api/web/v1/users?access-token=n-EJtZiejtz5RSVWe-U14G4kCnPWMKf0', user, { headers: this.headers })
.toPromise()
.then(res => res.json().data)
.catch(this.handleError);
}
You need to add your protocol for your URL. Otherwise, it's a relative URL:
.post('http://localhost/usmanProject/api/web/v1/users?access-token=n-EJtZiejtz5RSVWe-U14G4kCnPWMKf0', user, { headers: this.headers })
Your Url should be like url:string ="www.example.com";
It should not be like url:string =" 'www.example.com' ";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With