Laravel does not read HTTP request payload for PUT request

So, I am stumbling a bit since I realized that PHP will not read the body of an HTTP request from a PUT request. And when the header Content-Typein the request is set to application/json, there seems to be no way to get the body.

I use Laravel, which builds its request layer on top of the Symfony2 HttpFoundation lib.

I debugged this a bit using jQuery, and these are some sample queries:

By executing such a request, I can find the content through Input::getContent()

$.ajax({ 
    url: 'http://api.host/profiles/12?access_token=abcdef', 
    type: 'PUT', 
    data: {"profiles":[{"name":"yolanda ellis","email":"yolanda.ellis12@example.com"}]} 
});

I can not get content from file_get_contents('php://input'). jQuery by default sends data as application/x-www-form-urlencoded.

This becomes even more reasonable when I pass another Content-Type in the request. Same as Ember-Data:

$.ajax({ 
    url: 'http://api.host/profiles/12?access_token=abcdef', 
    type: 'PUT', 
    data: {"profiles":[{"name":"yolanda ellis","email":"yolanda.ellis12@example.com"}]},
    contentType: 'application/json' 
});

, , , . , Ember.js API.

?

Edit

, Chrome DevTools: http://pastebin.com/ZEjDAsmJ

, Laravel.

2:

, , php://input, Content-Type: application/json . , , @Mark_1, , , Laravel.

bshaffer/oauth2-server-php

+4
2

Input::json() , json- .

, , , , .

OAuth2\Request::createFromGlobals() ? Laravel, . ? http://bshaffer.imtqy.com/oauth2-server-php-docs/cookbook/laravel/ https://github.com/bshaffer/oauth2-server-httpfoundation-bridge, , httpfoundation ( Laravel).

- :

$bridgeRequest = \OAuth2\HttpFoundationBridge\Request::createFromRequest($request);
$server->grantAccessToken($bridgeRequest, $response);

, ..

+6

http://php.net/manual/en/features.file-upload.put-method.php

PUT php://input, fopen() fread(), . file_get_contents() .

?

+3

All Articles