I have been going trough this problem since yesterday, and while I have been searching through StackOverflow and other forums I couldn't find an answer to that problem.
I am looking to call a JSON array from our company's API, I was trying this code but it didn't work.
constructor(public http: Http) {
console.log('Data Service connected...');
}
getPosts() {
const url = 'example.com';
const header = new Headers();
header.set('user', 'foo');
header.append('password', 'bar');
header.append('Content-Type', 'application/json');
const options = new RequestOptions({headers: header});
return this.http.get(url, options).map(res => res.json());
}
However when I try to compile I get an error 401 (Unauthorized), is there any way to input the username and the password to get the response from the API?
EDIT
Here are the request headers:
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8,ar;q=0.6
Access-Control-Request-Headers:content-type,password,user
Access-Control-Request-Method:GET
Connection:keep-alive
Host:ess.gtslb.com
Origin:http://evil.com/
Referer:http://localhost:4200/
User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36