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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
chad
  • 564
  • 1
  • 4
  • 16
  • 1
    check this, https://stackoverflow.com/a/50135330/4399281 – Fateh Mohamed May 15 '18 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. – chad May 16 '18 at 13:38

1 Answers1

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

chad
  • 564
  • 1
  • 4
  • 16