HTML 表单 POST 跨域

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8497609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 11:58:53  来源:igfitidea点击:

HTML Form POST Cross Domain

htmlpostcross-domain

提问by jcmitch

I have a very simple HTML form that uses POST and its action calls a PHP script on my web server.

我有一个非常简单的 HTML 表单,它使用 POST 并且它的操作在我的 Web 服务器上调用一个 PHP 脚本。

Here is the kicker... the html that contains the form isn't hosted on the same server and exists in a different domain. Without bogging down this question with explanation this has to be done for business reasons. They need to exist within these specific domains.

这是踢球者...包含表单的 html 不是托管在同一台服务器上,而是存在于不同的域中。出于商业原因,必须在没有解释的情况下解决这个问题。它们需要存在于这些特定域中。

When I submit my form I access the PHP script correctly but then I try and pull out the POST data and it is gone. I'm thinking this is a security problem because I temporarily put the form on the same server as the PHP and it worked fine.

当我提交表单时,我正确访问了 PHP 脚本,但随后我尝试提取 POST 数据,但它消失了。我认为这是一个安全问题,因为我暂时将表单与 PHP 放在同一台服务器上并且运行良好。

Is there a way that I can get this to work with the two separate domains? Thanks in advance.

有没有办法让它与两个单独的域一起使用?提前致谢。

Edit:

编辑:

PHP Code (emailTemplate.php):

PHP 代码 (emailTemplate.php):

<?php
var_dump($_POST);
?>

HTML Form:

HTML 表单:

<form name="emailForm" id="emailForm" method="post" onsubmit="return beforeSubmit();" action="https://***.***.com/emailTemplate.php">
    <textarea rows="15" cols="75" id="myHtmlText" name="myHtmlText"></textarea>
    <input type="text" id="toAddr" name="toAddr" size="60"/>
    <input type="text" id="fromAddr" name="fromAddr" size="60"/>
    <input type="text" id="subjectLine" name="subjectLine" size="60"/>
    <input type="submit" name="Submit" value="Email Letter">
</form>

采纳答案by Aaron

If you're only experiencing the issue in IE, their XSS filter may be to blame. This articleprovides details for disabling it.

如果您只在 IE 中遇到此问题,则可能要怪他们的 XSS 过滤器。本文提供了禁用它的详细信息。

To avoid this problem entirely, try posting your form to a PHP script on your server, and in that script, create a cURL session that posts the form to the other script. The XSS transaction occurs independently of the client's web browser, averting these browser-based security restrictions in the process.

要完全避免此问题,请尝试将表单发布到服务器上的 PHP 脚本,并在该脚本中创建将表单发布到其他脚本的 cURL 会话。XSS 事务独立于客户端的 Web 浏览器发生,从而在此过程中避免了这些基于浏览器的安全限制。