簡體   English   中英

解析POST參數-不PUT / 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

POST行為符合預期時, PUT嘗試以{"input":""}返回: {"input":"fruit=orange&quantity=4"}

我讀到,apache應該不是問題。 那么有什么建議從哪里開始呢?

好吧,我已經弄清楚了:

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

做這項工作:-D

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM