1

I am sending a http.get request and expecting it to return a value, let say x. But the link is redirected and instead I get a 302 error.

When in network (web developer tools) I click on the original request, it goes to the redirekted link and the value of x is shown. Unfortunately, because x is in the new link, I cann't get it easily from response of my request. Does anyone know how I can get it? Thanks!

Here is my .ts file:

this.logingService.fun().subscribe(
            response => {
                this.x = response['x']; // I would like to get x value somehow like this, which doesn't work!
                console.log(response);
            },
            error => {
                console.log(error);                
            }
        );

Here is my serivse:

fun(): Observable<any>{
        return this.http.get(url);
    }
user9805040
  • 73
  • 1
  • 9
  • What does your `response` contain? – Manuel Tomás May 16 '22 at 20:30
  • This is the response: `HttpResponse {headers: HttpHeaders, status: 200, statusText: 'OK', url: 'https://redirectedlink', ok: true,} body: false headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ} ok: true status: 200 statusText: "OK" type: 4 url: "https://newlink" [[Prototype]]: HttpResponseBase` – user9805040 May 16 '22 at 20:48
  • I guess you can use `response.body()` as described in this answer https://stackoverflow.com/a/43394630/17503046 – Manuel Tomás May 16 '22 at 20:57
  • Let me know if it solved your issue so that I can add it as answer – Manuel Tomás May 16 '22 at 21:12
  • `response.body()` gives this error: ERROR TypeError: response.body is not a function. – user9805040 May 16 '22 at 21:30
  • sorry for the mistake, `body` is not a function, it is a property, so is should accessed via `response.body`. https://angular.io/api/common/http/HttpResponse#properties – Manuel Tomás May 16 '22 at 21:52
  • No problem, `body` is false. – user9805040 May 17 '22 at 07:50

0 Answers0