I'm having trouble making an http get request to an ASP.net Web API with user authentication. The goal is to get a JSON file from the API. I'm developing an Ionic Angular app and all I want to do currently is successfully make the get request.
Additional Context -When you visit the api in a browser, it requires a username and password -A NetworkCredential object is used for authentication in C#
Issue When I preview my app (with ionic serve), I get the following errors: -[Error] Preflight response is not successful -[Error] XMLHttpRequest cannot load http://notrealwebsite.com/api/example/3 due to access control checks. -[Error] Failed to load resource: Preflight response is not successful
What I've tried Right now my code looks like this:
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class ApiService {
httpOptions = {
headers: new HttpHeaders({
'Authorization': 'Basic ' + btoa('domain//username:password')
}),
}
constructor(private http: HttpClient) { }
getTest(id) {
return this.http.get(`http://notrealwebsite.com/api/example/${id}`, this.httpOptions);
}
}