如何在PHP中启用跨域POST-ing? [英] how to enable cross domain POST-ing in PHP?

查看:34
本文介绍了如何在PHP中启用跨域POST-ing?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 POST 数据从一个站点发送到另一个站点(两个站点都由我们开发).问题是如果从另一个域请求页面,则 POST 变量不可用.即使我在本地测试,但指定完整的url,POST数据也没有了.

I'm tying to send POST data from one site to another (both sites have been developed by us). The problem is that the POST variables are not available if the page is requested from another domain. Even if I test it locally, but specify the complete url, the POST data is gone.

所以,这会起作用:

<form method="POST" action="test.php">

但这不会:

<form method="POST" action="http://example.com/test.php">

这是页面的 HTML:

Here is the HTML for the page:

<html>
<head>
    <title></title>
</head>
<body>
    <form method="post" action="http://example.com/test.php">
        <input type="text" name="request" value="" id="" />
        <input type="submit" value="" id="" />
    </form>
</body>
</html>

在我得到这应该可行的评论后,我在另一台服务器上对其进行了测试,确实一切正常.这可能与启用第一台服务器 https 的事实有关.但如果是这种情况,我觉得很奇怪我确实得到了信息,但只是 POST 数据丢失了.

After the comments I got that this should work, I tested it on another server and there everything worked fine indeed. This might have something to do with the fact on the first server https is enabled. But if this is the case, I find it strange that I do get information back but that just the POST data has gone missing.

推荐答案

您所拥有的应该可以正常工作 - 表单出现在同源策略之前 - 您可以提交到不同的域.

What you have should work fine - forms came before the same-origin policy - you're allowed to submit to different domains.

如果我要冒险猜测,我会说有 301 或 302 重定向以某种方式进入那里?例如,请遵循 Firebug 的 HTTP 标头以确保.

If I were to hazard a guess, I'd say there's a 301 or 302 redirect getting in there somehow? Follow the HTTP headers with Firebug for example to be sure.

这篇关于如何在PHP中启用跨域POST-ing?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆