AngularJS $ http: how to avoid redirecting the following

In an AngularJS application, I am making a $ http.post call to the server url. The answer to the success of this URL is a 30x Redirect, my problem is that $ http.post strictly follows this redirect and returns the result of the final call in the result callback. I would like to intercept this redirect and manually redirect the user (changing the browser URL) to the last page. Is it possible?

+4
source share
1 answer

According to docs, a service $httpis the core Angular service that facilitates communication with remote HTTP servers through the browser XMLHttpRequest object or through JSONP.

Knowing this and knowing the specifications for XMLHttpRequest, it is probably not possible to intercept the redirect.

W3C spec for XMLHttpRequest says

If the response contains an HTTP status code of 301, 302, 303, 307, or 308

If the redirection violates the precautions in the form of an infinite loop, this is a network error.

Otherwise, follow these steps:

Specify the request URL of the URL passed by the location header.

If the original origin and source of the request URLs are of the same origin, transparently follow the redirects, observing the same origin to request event rules.

.

HTTP , .

, , Angular - , .

- $http , - cURL serverside ( , serveride), , , .

+6

Source: https://habr.com/ru/post/1569028/


All Articles