I am facing issues with my http
, header
, and RequestOption
in the API. I am working with Angular 7.1 and have tried various methods to resolve the problem without success.
The error message I am receiving is:
The token is not being passed in the header
This is the code snippet that I am currently using:
import { Http,RequestOptions,Headers } from '@angular/http';
import { keyframes } from '@angular/animations';
@Injectable({
providedIn: 'root'
})
export class UrlrequestService {
public headers = new Headers({ 'Content-Type': 'application/json'});
API:any = "http://api-url";
constructor(public http: Http) { }
get(url) {
this.headers.set('Authorization','Token '+localStorage.getItem('token'))
let options = { headers: this.headers };
console.log(options)
return this.http.get(this.API+url,options);
}