已解析POST参数-PUT not/LAMP服务器


POST parameters parsed - PUT not / LAMP server

我很难将参数传递到LAMP服务器:

  • Apache/2.2.22(Ubuntu)
  • PHP 5.3.10-1ubuntu3.6
  • 卷曲7.22.0

在服务器端,我使用slim进行REST操作。它似乎适用于GET/POST。我的测试实现如下:

 // Check the post route
 $app->post('/data', function () use ($app) {
        $app->response()->header("Content-Type", "application/json");
        $json_new_array["input"] = file_get_contents('php://input'); 
        $json_new_string = json_encode($json_new_array);
        echo $json_new_string;
    });
 // Check the put route
 $app->put('/data', function () use ($app) {
         $app->response()->header("Content-Type", "application/json");
         $json_new_array["input"] = file_get_contents('php://input'); 
         $json_new_string = json_encode($json_new_array);
         echo $json_new_string;
    });

以下是我在客户端尝试传递的参数:

curl -X PUT http://hostname/001_mockserver.php/data -d fruit=orange -d quantity=4 -i

curl -X POST http://hostname/001_mockserver.php/data -d fruit=orange -d quantity=4 -i

PUT尝试在{"input":""}中返回,而POST行为如预期:{"input":"fruit=orange&quantity=4"}

我读到apache不应该成为一个问题。那么有什么建议可以从哪里开始呢?

好吧,我已经想好了:

// Check the put route
$app->put('/data', function () use ($app) {
         $request = $app->request();
         $body = $request->getBody();
  });

执行以下操作:-D