my angular 6 get HTTP request with token authorization header isn't workingHow to add CORS request in header in Angular 5Laravel Dingo Api - How to return JSON formatted error response from API Controller?Angular - Set headers for every requestSet headers on get request angular 2Mysql: General error incorrect integer valueProtect api routes with tokens in a laravel - Angular applicationpostman: “Could not get any response” when passing laravel passport tokenMethodNotAllowedException Laravel Password Grant APIServer denies Authorization header and unable to authenticate with laravel passport in live serverBearer token not being accepted when calling out to api routes. 401 Laravel PassportLaravel API not working without CSRF token (and Headers globally messing around with me)
To get so rich that you are not in need of anymore money
What is the coil voltage of this contactor?
Algorithms vs LP or MIP
Billiard balls collision
Why is the UK so keen to remove the "backstop" when their leadership seems to think that no border will be needed in Northern Ireland?
Can RMSE and MAE have the same value?
Immediate Smaller Element Time Limit Exceeded
What does "rel" in `mathrel` and `stackrel` stands for?
How to gently end involvement with an online community?
Can you cast bonus action and reaction spells while already casting a spell?
What is the loud noise of a helicopter when the rotors are not yet moving?
How long do you think advanced cybernetic implants would plausibly last?
Can an ISO file damage—or infect—the machine it's being burned on?
Architectural feasibility of a tiered circular stone keep
How to change image size without scaling in GIMP
I don't have the theoretical background in my PhD topic. I can't justify getting the degree
Cooking Scrambled Eggs
What would make bones be of different colors?
How many lines of code does the original TeX contain?
Papers on arXiv solving the same problem at the same time
What should come first—characters or plot?
Removal of て in Japanese novels
Breaker Mapping Questions
Another solution to create a set with two conditions
my angular 6 get HTTP request with token authorization header isn't working
How to add CORS request in header in Angular 5Laravel Dingo Api - How to return JSON formatted error response from API Controller?Angular - Set headers for every requestSet headers on get request angular 2Mysql: General error incorrect integer valueProtect api routes with tokens in a laravel - Angular applicationpostman: “Could not get any response” when passing laravel passport tokenMethodNotAllowedException Laravel Password Grant APIServer denies Authorization header and unable to authenticate with laravel passport in live serverBearer token not being accepted when calling out to api routes. 401 Laravel PassportLaravel API not working without CSRF token (and Headers globally messing around with me)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
i am trying to do a get request with angular 6 to an API on a production server and i sent an authorization token header together with it but i keep getting
- XHR failed loading: OPTIONS "http://myserver/api/endpoint"
- OPTIONS "http://myserver/api/endpointnet ::ERR_EMPTY_RESPONSE"
- message: "Http failure response for (unknown url): 0 Unknown Error"
Error
Here is my code
authheader =
headers: new HttpHeaders(
'Authorization': 'Bearer '+this.tokenr,
'Content-Type': 'text/plain'
)
public async getUserInfo()
return new Promise(async resolve =>
this.http.get(this.realapi + '/user', this.authheader)
.map(data => <any>data)
.subscribe(data =>
resolve(data);
console.log(data, 'data here');
, err =>
console.log(err,'errorrr');
);
);
I am supposed to use this endpoint to fetch the user details after successful sign in from a laravel(passport) 5.7 api
Below is how i am handling my CORS and Preflight request in laravel
<?php
namespace AppHttpMiddleware;
use Closure;
use IlluminateSupportFacadesResponse;
class PreflightResponse
/**
* Handle an incoming request.
*
* @param IlluminateHttpRequest $request
* @param Closure $next
* @return mixed
*/
public function handle($request, Closure $next )
if ($request->getMethod() == "OPTIONS")
return Response::make('OK', 200, $headers);
$response = $next($request);
$response->header('Access-Control-Allow-Origin', '*');
$response->header('Access-Control-Allow-Methods', 'HEAD, GET, POST, PUT, DELETE, OPTIONS');
$response->header('Access-Control-Allow-Headers', 'Content-Type, Authorization, application/json');
return $response;
I added it to the $protected middleware(so it passes through all the request) in the kernel.php file
Funny enough, the POST http request works but the GET doesn't :(
POST request carries the data/parameter and 'Content-Type': 'application/x-www-form-urlencoded' header but the GET request just using the 'Authorization'; 'Bearer '+token
|
show 3 more comments
i am trying to do a get request with angular 6 to an API on a production server and i sent an authorization token header together with it but i keep getting
- XHR failed loading: OPTIONS "http://myserver/api/endpoint"
- OPTIONS "http://myserver/api/endpointnet ::ERR_EMPTY_RESPONSE"
- message: "Http failure response for (unknown url): 0 Unknown Error"
Error
Here is my code
authheader =
headers: new HttpHeaders(
'Authorization': 'Bearer '+this.tokenr,
'Content-Type': 'text/plain'
)
public async getUserInfo()
return new Promise(async resolve =>
this.http.get(this.realapi + '/user', this.authheader)
.map(data => <any>data)
.subscribe(data =>
resolve(data);
console.log(data, 'data here');
, err =>
console.log(err,'errorrr');
);
);
I am supposed to use this endpoint to fetch the user details after successful sign in from a laravel(passport) 5.7 api
Below is how i am handling my CORS and Preflight request in laravel
<?php
namespace AppHttpMiddleware;
use Closure;
use IlluminateSupportFacadesResponse;
class PreflightResponse
/**
* Handle an incoming request.
*
* @param IlluminateHttpRequest $request
* @param Closure $next
* @return mixed
*/
public function handle($request, Closure $next )
if ($request->getMethod() == "OPTIONS")
return Response::make('OK', 200, $headers);
$response = $next($request);
$response->header('Access-Control-Allow-Origin', '*');
$response->header('Access-Control-Allow-Methods', 'HEAD, GET, POST, PUT, DELETE, OPTIONS');
$response->header('Access-Control-Allow-Headers', 'Content-Type, Authorization, application/json');
return $response;
I added it to the $protected middleware(so it passes through all the request) in the kernel.php file
Funny enough, the POST http request works but the GET doesn't :(
POST request carries the data/parameter and 'Content-Type': 'application/x-www-form-urlencoded' header but the GET request just using the 'Authorization'; 'Bearer '+token
1
Can you share your code?
– MrWhiteNerdy
Mar 27 at 17:42
This may be a CORS problem, it happen when you make calls from different domains. stackoverflow.com/questions/47345282/…
– kaosdev
Mar 27 at 17:44
@kaosdev yes it is i will share my code real soon
– Natus Chike
Mar 27 at 17:56
@MrWhiteNerdy i have done that
– Natus Chike
Mar 27 at 18:09
Wich headers do you send back for an options request?
– kaosdev
Mar 27 at 18:49
|
show 3 more comments
i am trying to do a get request with angular 6 to an API on a production server and i sent an authorization token header together with it but i keep getting
- XHR failed loading: OPTIONS "http://myserver/api/endpoint"
- OPTIONS "http://myserver/api/endpointnet ::ERR_EMPTY_RESPONSE"
- message: "Http failure response for (unknown url): 0 Unknown Error"
Error
Here is my code
authheader =
headers: new HttpHeaders(
'Authorization': 'Bearer '+this.tokenr,
'Content-Type': 'text/plain'
)
public async getUserInfo()
return new Promise(async resolve =>
this.http.get(this.realapi + '/user', this.authheader)
.map(data => <any>data)
.subscribe(data =>
resolve(data);
console.log(data, 'data here');
, err =>
console.log(err,'errorrr');
);
);
I am supposed to use this endpoint to fetch the user details after successful sign in from a laravel(passport) 5.7 api
Below is how i am handling my CORS and Preflight request in laravel
<?php
namespace AppHttpMiddleware;
use Closure;
use IlluminateSupportFacadesResponse;
class PreflightResponse
/**
* Handle an incoming request.
*
* @param IlluminateHttpRequest $request
* @param Closure $next
* @return mixed
*/
public function handle($request, Closure $next )
if ($request->getMethod() == "OPTIONS")
return Response::make('OK', 200, $headers);
$response = $next($request);
$response->header('Access-Control-Allow-Origin', '*');
$response->header('Access-Control-Allow-Methods', 'HEAD, GET, POST, PUT, DELETE, OPTIONS');
$response->header('Access-Control-Allow-Headers', 'Content-Type, Authorization, application/json');
return $response;
I added it to the $protected middleware(so it passes through all the request) in the kernel.php file
Funny enough, the POST http request works but the GET doesn't :(
POST request carries the data/parameter and 'Content-Type': 'application/x-www-form-urlencoded' header but the GET request just using the 'Authorization'; 'Bearer '+token
i am trying to do a get request with angular 6 to an API on a production server and i sent an authorization token header together with it but i keep getting
- XHR failed loading: OPTIONS "http://myserver/api/endpoint"
- OPTIONS "http://myserver/api/endpointnet ::ERR_EMPTY_RESPONSE"
- message: "Http failure response for (unknown url): 0 Unknown Error"
Error
Here is my code
authheader =
headers: new HttpHeaders(
'Authorization': 'Bearer '+this.tokenr,
'Content-Type': 'text/plain'
)
public async getUserInfo()
return new Promise(async resolve =>
this.http.get(this.realapi + '/user', this.authheader)
.map(data => <any>data)
.subscribe(data =>
resolve(data);
console.log(data, 'data here');
, err =>
console.log(err,'errorrr');
);
);
I am supposed to use this endpoint to fetch the user details after successful sign in from a laravel(passport) 5.7 api
Below is how i am handling my CORS and Preflight request in laravel
<?php
namespace AppHttpMiddleware;
use Closure;
use IlluminateSupportFacadesResponse;
class PreflightResponse
/**
* Handle an incoming request.
*
* @param IlluminateHttpRequest $request
* @param Closure $next
* @return mixed
*/
public function handle($request, Closure $next )
if ($request->getMethod() == "OPTIONS")
return Response::make('OK', 200, $headers);
$response = $next($request);
$response->header('Access-Control-Allow-Origin', '*');
$response->header('Access-Control-Allow-Methods', 'HEAD, GET, POST, PUT, DELETE, OPTIONS');
$response->header('Access-Control-Allow-Headers', 'Content-Type, Authorization, application/json');
return $response;
I added it to the $protected middleware(so it passes through all the request) in the kernel.php file
Funny enough, the POST http request works but the GET doesn't :(
POST request carries the data/parameter and 'Content-Type': 'application/x-www-form-urlencoded' header but the GET request just using the 'Authorization'; 'Bearer '+token
edited Mar 27 at 18:59
Natus Chike
asked Mar 27 at 17:17
Natus ChikeNatus Chike
12 bronze badges
12 bronze badges
1
Can you share your code?
– MrWhiteNerdy
Mar 27 at 17:42
This may be a CORS problem, it happen when you make calls from different domains. stackoverflow.com/questions/47345282/…
– kaosdev
Mar 27 at 17:44
@kaosdev yes it is i will share my code real soon
– Natus Chike
Mar 27 at 17:56
@MrWhiteNerdy i have done that
– Natus Chike
Mar 27 at 18:09
Wich headers do you send back for an options request?
– kaosdev
Mar 27 at 18:49
|
show 3 more comments
1
Can you share your code?
– MrWhiteNerdy
Mar 27 at 17:42
This may be a CORS problem, it happen when you make calls from different domains. stackoverflow.com/questions/47345282/…
– kaosdev
Mar 27 at 17:44
@kaosdev yes it is i will share my code real soon
– Natus Chike
Mar 27 at 17:56
@MrWhiteNerdy i have done that
– Natus Chike
Mar 27 at 18:09
Wich headers do you send back for an options request?
– kaosdev
Mar 27 at 18:49
1
1
Can you share your code?
– MrWhiteNerdy
Mar 27 at 17:42
Can you share your code?
– MrWhiteNerdy
Mar 27 at 17:42
This may be a CORS problem, it happen when you make calls from different domains. stackoverflow.com/questions/47345282/…
– kaosdev
Mar 27 at 17:44
This may be a CORS problem, it happen when you make calls from different domains. stackoverflow.com/questions/47345282/…
– kaosdev
Mar 27 at 17:44
@kaosdev yes it is i will share my code real soon
– Natus Chike
Mar 27 at 17:56
@kaosdev yes it is i will share my code real soon
– Natus Chike
Mar 27 at 17:56
@MrWhiteNerdy i have done that
– Natus Chike
Mar 27 at 18:09
@MrWhiteNerdy i have done that
– Natus Chike
Mar 27 at 18:09
Wich headers do you send back for an options request?
– kaosdev
Mar 27 at 18:49
Wich headers do you send back for an options request?
– kaosdev
Mar 27 at 18:49
|
show 3 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55383056%2fmy-angular-6-get-http-request-with-token-authorization-header-isnt-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55383056%2fmy-angular-6-get-http-request-with-token-authorization-header-isnt-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Can you share your code?
– MrWhiteNerdy
Mar 27 at 17:42
This may be a CORS problem, it happen when you make calls from different domains. stackoverflow.com/questions/47345282/…
– kaosdev
Mar 27 at 17:44
@kaosdev yes it is i will share my code real soon
– Natus Chike
Mar 27 at 17:56
@MrWhiteNerdy i have done that
– Natus Chike
Mar 27 at 18:09
Wich headers do you send back for an options request?
– kaosdev
Mar 27 at 18:49