【问题标题】:POST data not received on server side服务器端未收到 POST 数据
【发布时间】:2015-10-24 08:30:14
【问题描述】:

我使用 Postman(Chrome 应用程序)将 POST 数据发送到 URL,但 PHP 文件永远不会收到 POST 数据,无论我在发送前如何更改内容类型。 Apache 上是否有停止从外部来源发布数据的服务器设置?

这是网址: http://friendesque.com/arranged/handler.php

这是 handler.php 文件的内容:

<?php
     echo("Inside file");

     echo("JSON:");
     $json = file_get_contents('php://input');
     echo($json);

     echo("POST:");
     print_r($_POST);

     echo("GET:");
     print_r($_GET);
?>

【问题讨论】:

  • 这真的很奇怪!可能是缓存问题。
  • 感谢您对此进行调查。我要删除这个问题。

标签: php apache post http-post


【解决方案1】:

为了使 $_POST 数组中的数据可用,应满足以下条件:

  1. 必须使用 POST HTTP 方法发送请求
  2. Content-Type 标头必须设置为 application/x-www-form-urlencoded
  3. 请求负载(正文)必须采用URL编码参数的形式,例如

    param1=a&param2=b
    

我向您的 URL 发送了一个满足这 3 个条件的请求,并在 $_POST 数组中获取了我的数据。

【讨论】:

    【解决方案2】:

    使用像 /index.php 这样的文件名。它会工作!

    【讨论】:

      猜你喜欢
      • 2017-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多