javascript - Angular, Not able to change Referer Header - Stack Overflow

I am accessing a third party service through the HttpClient of Angular.Before writing the code I made

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
Add a ment  | 

3 Answers 3

Reset to default 2

Is 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1741747741a4363832.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信