0

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>
Community
  • 1
  • 1
TDK
  • 161
  • 2
  • 13
  • 1
    You probably should send the data as POST body and not headers. – Mika Tuupola May 04 '16 at 15:17
  • @Mika Yeah... Exactly... I was sure it was an error in the actual code and not just an human mistake, haha. Classic way to lose time. – TDK May 04 '16 at 15:21

1 Answers1

0

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...

TDK
  • 161
  • 2
  • 13