while getting data from Bing Api using POSTMAN works fine.
but the same in angular not works, problem is in sending headers.
Error Response: 401 (Access Denied)
what am doing wrong here
import { HttpClient, HttpHeaders } from '@angular/common/http';
export class BingSearchComponent implements OnInit {
constructor(private http: HttpClient) { }
doSearch(input) {
console.log(input.value)
let subscriptionKey = 'XXXXXXXX';
let customConfigId = 'XXXXXXXX';
let searchTerm = 'microsoft';
let headers = new HttpHeaders();
let other_header =
headers.append('Ocp-Apim-Subscription-Key','XXXXXXXX'); //prints correctly here
console.log(other_header.get('Ocp-Apim-Subscription-Key'))
let url = 'https://api.cognitive.microsoft.com/bingcustomsearch/v7.0/search?'
+ 'q=' + searchTerm + '&customconfig=' + customConfigId
this.http.get(url, {headers: other_header}).subscribe(
res => console.log('handle your response', res),
msg => console.error(`Error: ${msg.status} ${msg.statusText}`)
);
}
}