【问题标题】:Is it possible redirect to a URL with a POST request rather than a GET request? [duplicate]是否可以使用 POST 请求而不是 GET 请求重定向到 URL? [复制]
【发布时间】:2011-10-20 00:52:28
【问题描述】:

可能重复:
Redirect with POST data

脚本是否可以通过 PHP 中的 POST 请求重定向到 URL?

我目前拥有的代码在页面主体加载后使用 javascript 提交表单。如果可能,我想避免这种情况并使用更强大的解决方案。

当前代码如下所示:

<?php
// Change this secret key so it matches the one in the imagemanager/filemanager config
$secretKey = "someSecretKey";

// Check here if the user is logged in or not

if (!isset($_SESSION["some_session"]))
    die("You are not logged in.");


// Override any config values here
$config = array();
//$config['filesystem.path'] = 'c:/Inetpub/wwwroot/somepath';
//$config['filesystem.rootpath'] = 'c:/Inetpub/wwwroot/somepath';
// Generates a unique key of the config values with the secret key
$key = md5(implode('', array_values($config)) . $secretKey);
?>

<html>
    <body onload="document.forms[0].submit();">
        <form method="post" action="<?php echo htmlentities($_GET['return_url']); ?>">
            <input type="hidden" name="key" value="<?php echo htmlentities($key); ?>" />
            <?php
            foreach($config as $key => $value) {
                echo '<input type="hidden" name="' . 
                          htmlentities(str_replace('.', '__', $key)) . '" 
                          value="' . htmlentities($value) . '" />';
            }
            ?>
        </form>
    </body>
</html>

这是MCImageManagerMCFileManager 文件包中的一个示例。

在这种情况下,从 curl 请求中回显响应将不起作用,因为在 HTML 中使用了相对文件路径,我无法轻松更改。

【问题讨论】:

标签: php httpwebrequest httprequest http-post get-request


【解决方案1】:

不,这是不可能的。

您必须使用 Javascript 提交表单或进行 AJAX POST。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-11
    • 1970-01-01
    • 2019-10-12
    相关资源
    最近更新 更多