【问题标题】:POST'ing to a server for the contents of an <iframe>POST 到服务器以获取 <iframe> 的内容
【发布时间】:2013-03-04 08:48:33
【问题描述】:

(第一次发帖,所以如果我在一些礼仪、标记等方面有所偏离,请多多包涵:))

服务器端:

iframe-contents.php:

<?PHP

if($_POST['test-post-parameter'] == 'test-post-value'){
echo 'test-post-parameter successfully detected as "test-post-value".';
} else {
echo 'test-post-parameter either absent or of a different value than "test-post-value". :(';
}
?>

好的,假设我使用

请求 iframe 内容

bash$ wget --post-data='test-post-parameter=test-post-value' -O - http://example.com/iframe-contents.php

结果是:

test-post-parameter successfully detected as "test-post-value".

但是,如果我要求它使用

`bash$ wget -O - http://example.com/iframe-contents.php`

我最终会得到:

test-post-parameter either absent or of a different value than "test-post-value

现在 - 假设我在服务器上有另一个文件,名为 index.html

<html><head><title>PAGE_TITLE</title></head>
<body>
<iframe width="100%" height="100%" src="iframe-contents.php" />
</body>

如果我尝试在浏览器中输入http://example.com/index.html,我的标题栏中会出现PAGE_TITlE,正文中会出现test-post-parameter either absent or of a different value than "test-post-value". :(

我的问题是:如何修改 iframe 元素以便获得?

test-post-parameter successfully detected as "test-post-value".

【问题讨论】:

    标签: html iframe xhtml


    【解决方案1】:

    你不能。您可以使用 GET 来完成。

    使用 POST: 也许只有当您创建一个临时 .php 页面时,该页面具有一个具有该 post 值的表单,以及一个自动发布表单并将您重定向到 iframe-contents.php 的 javascript 脚本

    类似这样的:

    temp-iframe.php

    <html><head>
    </head>
    <body onLoad="document.forms.myForm.submit()">
    <form name="myForm" id="myForm" method="POST" action="iframe-contents.php">
    <input type="hidden" name="test-post-parameter" value="test-post-value">
    </form>
    </body>
    </html>
    

    然后在 iframe src 中添加:temp-ifram.php

    希望对你有帮助。

    【讨论】:

      【解决方案2】:

      我不确定你是否可以对 post 参数执行此操作,但如果你将使用 get 方法,你可以显式传递参数:

      <html><head><title>PAGE_TITLE</title></head>
      <body>
      <iframe width="100%" height="100%" src="iframe-contents.php?test-post-parameter=value" />
      </body>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-07-21
        • 2017-03-02
        • 1970-01-01
        • 2014-08-06
        • 2015-01-26
        • 1970-01-01
        相关资源
        最近更新 更多