0

I am trying to access the Location HttpResponse header value. There are plenty of examples of how this should be handled but I have been unable to get it to work.

HTTP Get call in service class

public beginIntegration(vendorName: string, baseUrl: string): Observable<HttpResponse<object>> {
    return this.http.get<any>(`${baseUrl}${this.url}/begin-integration/${vendorName}`, { withCredentials: true, observe: 'response' });
}

Component Subscribe Request:

private clickBeginIntegrationButton(vendorName: string): void {

    this.integrationsMarketplaceService.beginIntegration(vendorName, this.configuration.webLinkIntegrationsApiBaseUrl)
      .subscribe(
        (res) => {
          this.banner.showSuccess(`Redirect URL - ${res.headers.get('Location')}`);
        },
        (error) => {
          this.banner.showError('Error Getting Redirect URL');
        }
      );
}

The aren't any header values, it's not just that the location property doesn't exist. What am I missing?

2
  • 1
    check this, stackoverflow.com/a/50135330/4399281 Commented May 15, 2018 at 22:06
  • I saw that post when I was attempting to resolve the issue. As you can see, I have the observe property set to 'response' and I am getting the entire response object returned as the observable. However, the response object's header doesn't contain any values. Commented May 16, 2018 at 13:38

1 Answer 1

0

After looking at the post that Fateh mentioned, in his comment above, there was another link to a github post, https://github.com/angular/angular/issues/13226, that ultimately identified this as a CORS issue. I was able to update my Web API's CORS configuration to expose specific header properties. The property I wanted was Location so I added Location to the comma-delimited list of properties in the exposedHeaders property of the EnableCors method.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.