簡體   English   中英

在客戶端接收重定向的 POST 請求

[英]POST request to receive redirect on client side

我有一個正在運行的服務,它接收一個 POST 請求並返回一個重定向。 我已經能夠使用 Postman 和 nghttp2.org (httpbin.org) 對此進行測試。

在郵遞員上,當我發帖時:

https://nghttp2.org/httpbin/redirect-to?url=https%3A%2F%2Fwww.google.com

收到的html是google.com主頁

但是要在客戶端網頁上運行它,我有以下代碼:

<html>
    <script type="text/javascript">

        function redirect() {
            fetch('https://nghttp2.org/httpbin/redirect-to?url=https%3A%2F%2Fwww.google.com', {
                headers: { 
                    'Content-Type': 'application/x-www-form-urlencoded',
                    'Accept': 'text/html',
                    'Access-Control-Allow-Origin': '*'
                },
                method: 'POST', 
                mode: 'no-cors',
                redirect: 'follow',
            })
        }

        redirect();

    </script>
</html>

我在服務器上運行這個網頁,它沒有重定向。

加載此網頁時是否可以讓頁面自動重定向? 或者我可以采取另一種方法。 我確實需要將請求設為 POST,並且由於 cookie 處理,我確實需要在客戶端進行重定向。

提前加油!

Fetch 不會直接重定向到服務器請求的另一個頁面。 但是它可以告訴您服務器正在請求重定向到另一個頁面,您可以相應地處理它。 您可以在https://developer.mozilla.org/en-US/docs/Web/API/Response/redirected上找到更多信息

暫無
暫無

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

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