dpbe81245 2016-05-04 14:52
浏览 79
已采纳

使用Slim 3获取POST PUT参数

I'm trying to build a full REST API with Slim 3. It was quite easy with Slim 2. But now I've got some issues.

The POST and PUT route does not work has expected. I can't get the parameters. I found the $request->getHeaders() on the documentations, which works but instead of getting for exemple the parameter length, I get HTTP_LENGHT and every parameters has this HTTP_ prefixe.

I found this question but $request->getParsedBody() return an empty array for me.

I'm testing my API with Advanced REST Client and this is an example of what I send as a POST request:

POST /test/barrier HTTP/1.1
 HOST: mydomain.com
 start_lng: 2.6423183977058
 start_lat: 56.865296679535
 type: Something
 comment: testcomment
 due_date: null
 content-type: application/x-www-form-urlencoded

I'm using Slim 3.3.0.

Here is an example of what I get with $request->getHeaders():

["HTTP_START_LAT"]=>
  array(1) {
    [0]=>
    string(15) "56.865296679535"
  }
  ["HTTP_START_LNG"]=>
  array(1) {
    [0]=>
    string(15) "2.6423183977058"
  }

One strange thing is, if I try do to $request->hasHeader('length'); I get the value of my parameter, so that means, the name are correct. I really don't understand.

I just want to get the array of the parameters as $app->request->post() used to do in Slim 2.*. Thanks.

My .htaccess is like this:

RewriteEngine On

RewriteBase /test

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

<files db.config.ini>
    deny from all
</files>
  • 写回答

1条回答 默认 最新

  • duanhoupeng6642 2016-05-04 15:20
    关注

    Ok. My mistake, I just got it wrong in the testing app. I was writing all my parameters as headers form an not as data form...

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

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器