dsk49208 2019-04-05 05:51
浏览 222
已采纳

Slim Framework:方法不允许方法不允许。 必须是以下之一:POST

I'm setting up a REST-server in PHP and want to allow the client to use an endpoint with different methods like GET, POST, PUT, DELETE, ... But there is a problem when I try adding the function for the POST method: The application runs the function for GET if I try to access it with POST via Postman.

I already tried to comment the GET function but if I do this, I get an error 405.

// Just a testing function for POST
$app->post('/users', function (Request $request, Response $response, array $args)
{
    $user = $request->getParsedBody();
    $response->getBody()->write(json_encode($user->getWrapperClass()));
    return $response->withHeader('Content-Type', 'application/json');
});

Anyone can help me?

  • 写回答

1条回答 默认 最新

  • dongmi19720408 2019-04-09 09:16
    关注

    I have found the problem: It was not Postman and not my code. The problem was the URL entered in Postman: It was a http URL and the server has an automatic redirection to https. During this process the HTTP method just changed to GET instead of POST, PUT or anything else... Now changed the URL to https: It works fine now!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?