簡體   English   中英

Flutter web 未重定向到服務器端端點

[英]Flutter web not redirecting to server-side endpoint

我在我的服務器中創建了一個端點,其狀態代碼為 303,並重定向到預構建的條帶結帳頁面。 雖然,當我使用此http package發布到此端點時,我的 flutter 應用程序不會重定向到結帳頁面。 相反,它會響應一個到重定向位置 header 的獲取請求,狀態代碼為 200。結帳頁面永遠不會重定向到。

response = await http.post(Uri.parse('myURL'));

試圖阻止發布請求響應獲取請求,我試圖捕獲位置 header 並使用此url-launcher package重定向到它。 但這會引發錯誤,因為它仍在重定向到結帳頁面鏈接的獲取請求,並且沒有位置 header。

      http.Request request = http.Request("post", Uri.parse('myURL'))..followRedirects=false..maxRedirects=0;
      http.Client baseClient = http.Client();
      http.StreamedResponse response = await baseClient.send(request);
      Uri redirectUri = Uri.parse(response.headers['location']!);
      if (!await launchUrl(redirectUri, mode: LaunchMode.externalApplication)) {
        throw 'Could not launch $redirectUri';
      }

如果有人對如何讓我的 flutter 應用程序重定向到狀態代碼 303 位置 header 鏈接有任何想法,我將不勝感激。 謝謝。

我從來沒有想過如何讓 Flutter 從發布請求重定向到新頁面,但我想出了一個不同的解決方案。 使用 'dart:html' package,我能夠將其 window 重定向選項與 url 一起使用。 在我的 api 中,我返回了我想通過正文重定向到的 url。

String redirectUri = response.body;
html.window.open(redirectUri, "_self");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM