【问题标题】:Form POST from other domain is empty in PHP来自其他域的表单 POST 在 PHP 中为空
【发布时间】:2018-01-17 10:45:16
【问题描述】:

从另一个域发布表单(使用 POST)时,我的 POST 集合为空。 当我在同一个域上使用一个简单的 HTML 页面进行测试时,它可以工作。

这是我的 PHP 代码:

<?php
header("access-control-allow-origin: *");
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 'On');
ini_set("allow_url_fopen", true);
echo("input: " . file_get_contents("php://input"));
?>

有人有想法吗?会不会是服务器设置/配置?

这些是我返回的标题(使用 Postman 时):

Connection →Upgrade, Keep-Alive
Content-Encoding →gzip
Content-Length →27
Content-Type →text/html; charset=UTF-8
Date →Wed, 17 Jan 2018 10:39:26 GMT
Keep-Alive →timeout=2, max=100
Server →Apache/2.4.29 (Unix) OpenSSL/1.0.2k
Upgrade →h2,h2c
Vary →Accept-Encoding,User-Agent
X-Powered-By →PHP/7.2.0
access-control-allow-origin →*

【问题讨论】:

  • 请分享请求代码。

标签: php apache post http-post


【解决方案1】:

php://input 是一个只读流,从请求体中读取原始数据。例如,当数据以 json 格式出现时,它很有用。当您使用 enctype=multipart/formdata 发布表单时,数据(键值对)在 $_POST 全局变量中,而 php://input 不可用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-03
    • 2018-07-05
    相关资源
    最近更新 更多