Angular 4 - Fetch information sent in header of the url





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have an angular page and is being rendered through a component - say DashboardComponent. A third party site redirects to my angular page and set some information, like userId, in the header(not in the url parameter).



Now I would like to know that how will I fetch this header information in my angular component (or in angular project also will do if there is a proper way to do so.)?



My thought goes to might be we can get it from index.html, but its being an html file, I am not sure if this is possible.



Please help in this.










share|improve this question


















  • 1





    Possible duplicate of How do I access the HTTP request header fields via JavaScript?

    – jonrsharpe
    Jan 3 at 9:23


















0















I have an angular page and is being rendered through a component - say DashboardComponent. A third party site redirects to my angular page and set some information, like userId, in the header(not in the url parameter).



Now I would like to know that how will I fetch this header information in my angular component (or in angular project also will do if there is a proper way to do so.)?



My thought goes to might be we can get it from index.html, but its being an html file, I am not sure if this is possible.



Please help in this.










share|improve this question


















  • 1





    Possible duplicate of How do I access the HTTP request header fields via JavaScript?

    – jonrsharpe
    Jan 3 at 9:23














0












0








0








I have an angular page and is being rendered through a component - say DashboardComponent. A third party site redirects to my angular page and set some information, like userId, in the header(not in the url parameter).



Now I would like to know that how will I fetch this header information in my angular component (or in angular project also will do if there is a proper way to do so.)?



My thought goes to might be we can get it from index.html, but its being an html file, I am not sure if this is possible.



Please help in this.










share|improve this question














I have an angular page and is being rendered through a component - say DashboardComponent. A third party site redirects to my angular page and set some information, like userId, in the header(not in the url parameter).



Now I would like to know that how will I fetch this header information in my angular component (or in angular project also will do if there is a proper way to do so.)?



My thought goes to might be we can get it from index.html, but its being an html file, I am not sure if this is possible.



Please help in this.







angular http-headers






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 9:16









Ritesh BathwalRitesh Bathwal

6




6








  • 1





    Possible duplicate of How do I access the HTTP request header fields via JavaScript?

    – jonrsharpe
    Jan 3 at 9:23














  • 1





    Possible duplicate of How do I access the HTTP request header fields via JavaScript?

    – jonrsharpe
    Jan 3 at 9:23








1




1





Possible duplicate of How do I access the HTTP request header fields via JavaScript?

– jonrsharpe
Jan 3 at 9:23





Possible duplicate of How do I access the HTTP request header fields via JavaScript?

– jonrsharpe
Jan 3 at 9:23












1 Answer
1






active

oldest

votes


















0














If you had an http service file you could use something like this:



this.httpService.getList()
.subscribe((res) => {

console.log(res.headers.get('x-paging-pagecount'));

});


This for example would get the value of "x-paging-pagecount" from the headers.






share|improve this answer
























  • Its a third party website, redirecting to my angular site. So how can a third party site call service defined at my end. I need to fetch data from headers set by third party site when they are redirecting to a url on my angular page.

    – Ritesh Bathwal
    Jan 3 at 9:50











  • In short a third party site can't call your service, because all the code gets minified and you won't know what it is called. Your third party site will just have to know the api line that it wants to call.

    – Andrew Junior Howard
    Jan 3 at 10:35











  • Hi Andrew. The scenario is that third party site will be sending request to my angular page route (by redirecting to my angular route) and in this requst it will be setting up the header. So I would like to know is it possible to fetch header information from angular end for this request? If yes, then how? If no then why?

    – Ritesh Bathwal
    Jan 3 at 11:16













  • In that scenerio you could set a queryparam from the third party site to go to your angular route, for example "example.com?thirdparty=true" and then you just put some if statement logic to get the headers. You could also use this approach to have 2 different api calls if they need different headers being set.

    – Andrew Junior Howard
    Jan 3 at 11:45











  • Cant add the information in the query params as it is sensitive info. (Its user access token). So that will compromise the security. Any other solution?

    – Ritesh Bathwal
    Jan 4 at 6:30












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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54019300%2fangular-4-fetch-information-sent-in-header-of-the-url%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














If you had an http service file you could use something like this:



this.httpService.getList()
.subscribe((res) => {

console.log(res.headers.get('x-paging-pagecount'));

});


This for example would get the value of "x-paging-pagecount" from the headers.






share|improve this answer
























  • Its a third party website, redirecting to my angular site. So how can a third party site call service defined at my end. I need to fetch data from headers set by third party site when they are redirecting to a url on my angular page.

    – Ritesh Bathwal
    Jan 3 at 9:50











  • In short a third party site can't call your service, because all the code gets minified and you won't know what it is called. Your third party site will just have to know the api line that it wants to call.

    – Andrew Junior Howard
    Jan 3 at 10:35











  • Hi Andrew. The scenario is that third party site will be sending request to my angular page route (by redirecting to my angular route) and in this requst it will be setting up the header. So I would like to know is it possible to fetch header information from angular end for this request? If yes, then how? If no then why?

    – Ritesh Bathwal
    Jan 3 at 11:16













  • In that scenerio you could set a queryparam from the third party site to go to your angular route, for example "example.com?thirdparty=true" and then you just put some if statement logic to get the headers. You could also use this approach to have 2 different api calls if they need different headers being set.

    – Andrew Junior Howard
    Jan 3 at 11:45











  • Cant add the information in the query params as it is sensitive info. (Its user access token). So that will compromise the security. Any other solution?

    – Ritesh Bathwal
    Jan 4 at 6:30
















0














If you had an http service file you could use something like this:



this.httpService.getList()
.subscribe((res) => {

console.log(res.headers.get('x-paging-pagecount'));

});


This for example would get the value of "x-paging-pagecount" from the headers.






share|improve this answer
























  • Its a third party website, redirecting to my angular site. So how can a third party site call service defined at my end. I need to fetch data from headers set by third party site when they are redirecting to a url on my angular page.

    – Ritesh Bathwal
    Jan 3 at 9:50











  • In short a third party site can't call your service, because all the code gets minified and you won't know what it is called. Your third party site will just have to know the api line that it wants to call.

    – Andrew Junior Howard
    Jan 3 at 10:35











  • Hi Andrew. The scenario is that third party site will be sending request to my angular page route (by redirecting to my angular route) and in this requst it will be setting up the header. So I would like to know is it possible to fetch header information from angular end for this request? If yes, then how? If no then why?

    – Ritesh Bathwal
    Jan 3 at 11:16













  • In that scenerio you could set a queryparam from the third party site to go to your angular route, for example "example.com?thirdparty=true" and then you just put some if statement logic to get the headers. You could also use this approach to have 2 different api calls if they need different headers being set.

    – Andrew Junior Howard
    Jan 3 at 11:45











  • Cant add the information in the query params as it is sensitive info. (Its user access token). So that will compromise the security. Any other solution?

    – Ritesh Bathwal
    Jan 4 at 6:30














0












0








0







If you had an http service file you could use something like this:



this.httpService.getList()
.subscribe((res) => {

console.log(res.headers.get('x-paging-pagecount'));

});


This for example would get the value of "x-paging-pagecount" from the headers.






share|improve this answer













If you had an http service file you could use something like this:



this.httpService.getList()
.subscribe((res) => {

console.log(res.headers.get('x-paging-pagecount'));

});


This for example would get the value of "x-paging-pagecount" from the headers.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 3 at 9:35









Andrew Junior HowardAndrew Junior Howard

93111328




93111328













  • Its a third party website, redirecting to my angular site. So how can a third party site call service defined at my end. I need to fetch data from headers set by third party site when they are redirecting to a url on my angular page.

    – Ritesh Bathwal
    Jan 3 at 9:50











  • In short a third party site can't call your service, because all the code gets minified and you won't know what it is called. Your third party site will just have to know the api line that it wants to call.

    – Andrew Junior Howard
    Jan 3 at 10:35











  • Hi Andrew. The scenario is that third party site will be sending request to my angular page route (by redirecting to my angular route) and in this requst it will be setting up the header. So I would like to know is it possible to fetch header information from angular end for this request? If yes, then how? If no then why?

    – Ritesh Bathwal
    Jan 3 at 11:16













  • In that scenerio you could set a queryparam from the third party site to go to your angular route, for example "example.com?thirdparty=true" and then you just put some if statement logic to get the headers. You could also use this approach to have 2 different api calls if they need different headers being set.

    – Andrew Junior Howard
    Jan 3 at 11:45











  • Cant add the information in the query params as it is sensitive info. (Its user access token). So that will compromise the security. Any other solution?

    – Ritesh Bathwal
    Jan 4 at 6:30



















  • Its a third party website, redirecting to my angular site. So how can a third party site call service defined at my end. I need to fetch data from headers set by third party site when they are redirecting to a url on my angular page.

    – Ritesh Bathwal
    Jan 3 at 9:50











  • In short a third party site can't call your service, because all the code gets minified and you won't know what it is called. Your third party site will just have to know the api line that it wants to call.

    – Andrew Junior Howard
    Jan 3 at 10:35











  • Hi Andrew. The scenario is that third party site will be sending request to my angular page route (by redirecting to my angular route) and in this requst it will be setting up the header. So I would like to know is it possible to fetch header information from angular end for this request? If yes, then how? If no then why?

    – Ritesh Bathwal
    Jan 3 at 11:16













  • In that scenerio you could set a queryparam from the third party site to go to your angular route, for example "example.com?thirdparty=true" and then you just put some if statement logic to get the headers. You could also use this approach to have 2 different api calls if they need different headers being set.

    – Andrew Junior Howard
    Jan 3 at 11:45











  • Cant add the information in the query params as it is sensitive info. (Its user access token). So that will compromise the security. Any other solution?

    – Ritesh Bathwal
    Jan 4 at 6:30

















Its a third party website, redirecting to my angular site. So how can a third party site call service defined at my end. I need to fetch data from headers set by third party site when they are redirecting to a url on my angular page.

– Ritesh Bathwal
Jan 3 at 9:50





Its a third party website, redirecting to my angular site. So how can a third party site call service defined at my end. I need to fetch data from headers set by third party site when they are redirecting to a url on my angular page.

– Ritesh Bathwal
Jan 3 at 9:50













In short a third party site can't call your service, because all the code gets minified and you won't know what it is called. Your third party site will just have to know the api line that it wants to call.

– Andrew Junior Howard
Jan 3 at 10:35





In short a third party site can't call your service, because all the code gets minified and you won't know what it is called. Your third party site will just have to know the api line that it wants to call.

– Andrew Junior Howard
Jan 3 at 10:35













Hi Andrew. The scenario is that third party site will be sending request to my angular page route (by redirecting to my angular route) and in this requst it will be setting up the header. So I would like to know is it possible to fetch header information from angular end for this request? If yes, then how? If no then why?

– Ritesh Bathwal
Jan 3 at 11:16







Hi Andrew. The scenario is that third party site will be sending request to my angular page route (by redirecting to my angular route) and in this requst it will be setting up the header. So I would like to know is it possible to fetch header information from angular end for this request? If yes, then how? If no then why?

– Ritesh Bathwal
Jan 3 at 11:16















In that scenerio you could set a queryparam from the third party site to go to your angular route, for example "example.com?thirdparty=true" and then you just put some if statement logic to get the headers. You could also use this approach to have 2 different api calls if they need different headers being set.

– Andrew Junior Howard
Jan 3 at 11:45





In that scenerio you could set a queryparam from the third party site to go to your angular route, for example "example.com?thirdparty=true" and then you just put some if statement logic to get the headers. You could also use this approach to have 2 different api calls if they need different headers being set.

– Andrew Junior Howard
Jan 3 at 11:45













Cant add the information in the query params as it is sensitive info. (Its user access token). So that will compromise the security. Any other solution?

– Ritesh Bathwal
Jan 4 at 6:30





Cant add the information in the query params as it is sensitive info. (Its user access token). So that will compromise the security. Any other solution?

– Ritesh Bathwal
Jan 4 at 6:30




















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54019300%2fangular-4-fetch-information-sent-in-header-of-the-url%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]