[英]POST parameters parsed - PUT not / LAMP server
我在將參數傳遞到LAMP服務器時遇到困難:
在服務器端,我將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.