admin 管理员组文章数量: 1086019
I am accessing a third party service through the HttpClient of Angular.
Before writing the code I made some test with Postman , if could access this third party service. And I notice that i have to set Referer
to name of domain of the third pary in order to get a successful response from the third party. So in order to get a successful response I should tell the third party that this request is originating from a specific url.
The problem is that i cannot set the Referer header from angular. Is it possible to set the Referer Header from angular? How can i achieve to modify the Referer Header? I have simplified the code by removing the business logic. Below is what i am trying to do to achieve this.
var serviceUrl = "";
let httpOptions = {
headers: new HttpHeaders({
'Referer': ''
})
};
let formData = new FormData();
formData.append("x","z");
formData.append("y","z");
this.httpClient.post(serviceUrl,formData,httpOptions).subscribe(response => {
console.log(response);
});
I am accessing a third party service through the HttpClient of Angular.
Before writing the code I made some test with Postman , if could access this third party service. And I notice that i have to set Referer
to name of domain of the third pary in order to get a successful response from the third party. So in order to get a successful response I should tell the third party that this request is originating from a specific url.
The problem is that i cannot set the Referer header from angular. Is it possible to set the Referer Header from angular? How can i achieve to modify the Referer Header? I have simplified the code by removing the business logic. Below is what i am trying to do to achieve this.
var serviceUrl = "https://xxx.yyy.zzz";
let httpOptions = {
headers: new HttpHeaders({
'Referer': 'https://xx.yyy.xx'
})
};
let formData = new FormData();
formData.append("x","z");
formData.append("y","z");
this.httpClient.post(serviceUrl,formData,httpOptions).subscribe(response => {
console.log(response);
});
Share
Improve this question
asked Feb 24, 2020 at 14:07
user12827457user12827457
3 Answers
Reset to default 2Is it possible to set the Referer Header from angular?
No. Referer
is a forbidden header name (in the context of setting a request header from JS).
It would be a major security problem is it was possible.
I wan't able to change the referer header from angular by specifying the header in the the httpclient request.
But I found a workaround that solves perfectly my problem. I installed the chrome extension : ModHeader (link -> https://chrome.google./webstore/detail/modheader/idgpnmonknjnojddfkpgkljpfnnfcklj).
After installation of extension is finished . I have specified the request header that i want to add. And also I have specified the filter for which requests uri are the header going to be add. Below is the image of plugin. You just need to configure the filter uri that you want to add those headers.
That is because the browser of the user of your angular app will not allow to change the referer header. If you want to change it to an arbitrary value you would need to have access to a browser plugin or another kind of application installed on their machine.
Most modern browsers support the referrer-policy which will allow you to hide the referer header but changing it is not possible.
本文标签: javascriptAngular Not able to change Referer HeaderStack Overflow
版权声明:本文标题:javascript - Angular, Not able to change Referer Header - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1741747742a2312934.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论