admin管理员组

文章数量:1208155

I am working on a dart/flutter web app with a custom back-end. Both use dart and the front-end is supposed to make an API call against the back-end which then anwsers with a redirect to an external web page.

However, when the api call is made I can see the the redirects happening in the network tab but no new page is opening. Instead the http.post (or http.head request since I tried both) does just go through all the redirects and receives a code 200 at the end. So, the page is not opening and I also cannot intercept the redirect location from the initial API response because the response I receive in the frontend is the one from the redircets which is the one with code 200 and not "Location" header.

I tried disabling automatic redirects which does not seem to work as also explained here:

How to not follow redirects with Darts http-package? request.followRedirects = false is set

Generally I also found some seemingly contradictory information:

flutter/dart http package not redirecting to page

How to get redirect url in Dart?

So, http.post follows redirects automatically but also cannot handle them apparently? And the suggestion to disable it also does not work. This leaves me quite confused as I do not see a way to open a new page this way. Preferably I would want to use universal_html to use:

html.window.open(Uri.parse(location!) as String, 'Login');

However, as mentioned previously I cannot get the location from the API call. I would also like to avoid hardcoding the address in the front-end if possible.

本文标签: flutterCan you open a new page from an API redirectStack Overflow