【问题标题】:php://input empty on Azurephp://input 在 Azure 上为空
【发布时间】:2014-12-23 16:46:11
【问题描述】:

我正在使用 AngularJS 向运行 PHP 5.4 的 Azure IIS 发布一个复杂的 JSON 对象:

var request = $http({
    method: "post",
    url: "/php/mail.php",
    data: $scope.contactForm,
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
    }
});

我的 PHP 脚本由这两行组成:

$data = json_decode(file_get_contents("php://input"));
print_r($data);

在尝试读取 POST 数据时,所有数组($_POST$_REQUESTphp://input)都是空的。 没有重定向会杀死POST 数据并回显$_SERVER['CONTENT_TYPE'] 返回'application/x-www-form-urlencoded'

【问题讨论】:

  • 它是否可以在 Azure 之外的服务器上运行?

标签: php json angularjs post azure


【解决方案1】:

由于您的 PHP 需要 JSON,因此您的 Content-Type 不正确。此外,您需要对数据进行字符串化,因此您的 AngularJS 代码如下所示:

var request = $http({
    method: "post",
    url: "/php/mail.php",
    data: JSON.stringify($scope.contactForm),
    headers: {
        'Content-Type': 'application/json'
    }
});

【讨论】:

    猜你喜欢
    • 2016-06-02
    • 2018-07-30
    • 1970-01-01
    • 2018-08-08
    • 1970-01-01
    • 2017-11-17
    • 1970-01-01
    • 1970-01-01
    • 2018-06-08
    相关资源
    最近更新 更多