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 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题