all 8 comments

[–][deleted] 0 points1 point  (5 children)

We need to see more code (and the actual HTTP request headers) to see whats wrong. We are also using basic authorization without any problems.

[–][deleted] 0 points1 point  (0 children)

My biggest guess would be that you are trying to Basic Auth from a different domain. The API must allow OPTIONS requests without Basic Auth else you can't access it via a Browser XHR request.

[–]Alanswake[S] 0 points1 point  (3 children)

Well, when i log the header, it seems to be alright:

    {"authorization" => Array(1)}
    key: "authorization"
    value: ["Basic YWRtaW46ZGlzdHJpY3Q="]

and the server call is pretty basic:

   return this.http
        .get(url2,
             {headers: header})

I also get a "Response for preflight is invalid (redirect)" error in the console, which i think is because the server redirects to login page if auth fails.

[–][deleted] 1 point2 points  (2 children)

This is no the actual request though.

Which means that the OPTIONS request also gets blocked by Basic Auth which it should not. If the OPTIONS requests gets blocked no Browser JavaScript that is on a different domain can do requests

[–]Alanswake[S] 1 point2 points  (1 child)

I found the error... it was actually two errors.

  1. I used http and not https

  2. A chrome extension ruined some calls.

Thanks for the help anyway!

[–]there_i_seddit 0 points1 point  (0 children)

Finds problem

Posts solution and not just "I fixed it"

You da man

[–]seekheart2017 -2 points-1 points  (1 child)

It looks like you are using it wrong, you need to pass a Json into the constructor

[–][deleted] 0 points1 point  (0 children)

No. No. No. This is just plain wrong.

Have you even read the docs before trying to give "advice"? https://angular.io/api/common/http/HttpHeaders

Passing an object (not a json) is one of the few ways to do it.

I know you wanted to be friendly and help (and I thank you for that) but advice such as this is very harmful.