2

Currently facing a problem where the request to Azure Search API is returning an "Unknown error".

I got the .Get() request working in postman and thought it would be theoretically the same set-up in Angular using the Http Client.

export class AzureSearchConfigComponent implements OnInit {
synonyms: any[];
private synonymUrl = 'https://name.search.windows.net/synonymmaps?api-version=2017-11-11'
constructor(private http: HttpClient) { }

ngOnInit() 
{
let headers = new HttpHeaders();
headers = headers
  .set('Content-Type', 'application/json')
  .set('api-key','xxxx-xxx-xxxxx');

this.http.get(this.synonymUrl,{headers:headers})
  .subscribe(
    repsonse => {
      console.log(repsonse);
    }
  );
}
}

Error message:

ERROR HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: null, ok: false, …}

Postman Response:

enter image description here

also getting the error:

Response for preflight is invalid (redirect)

8
  • As I state, it works with postman, [name] would be the name of my azure subscription, just didn't want it public. Commented May 30, 2018 at 15:07
  • Oh shut, I didn't see that Commented May 30, 2018 at 15:09
  • I've read that it's something to do with CORS, but i'm running the angular app locally on localhost:4200, tried disabling internet security on chrome but still no luck Commented May 30, 2018 at 15:10
  • Hmm, if it is CORS then the console should tell you that Commented May 30, 2018 at 15:11
  • Just posted the other error i ge tbefore the "unknown error" : Response for preflight is invalid (redirect) Commented May 30, 2018 at 15:13

1 Answer 1

1

Turns out a temporary solution is to disable web security on google chrome, by running the following command into cmd (after locating the chrome.exe in program x86)

--disable-web-security --user-data-dir

This is because the CORS settings in chrome causes a redirect flight, I am currently also trying to host on a proxy to see if the issue can be resolved without disabling web security, will post here if successful

Sign up to request clarification or add additional context in comments.

1 Comment

This is the only thing that has worked for me while testing typescript with Rider. It only seems to work with Chrome directly and not any Chrome-based browsers. I could not get Brave or Edge to work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.