Post/Put multipart/form-data

913
.

Интересное поведение...
Это не суть важно, но скажу: юзаю бандл от симфони FOSRestBundle.

Есть два метода в контроллере post и put. В них передаю данные с form-data через postman.
В заголовке передается Content-type: application/json.
В метод сделан просто вывод данных с $_REQUEST...

Теперь самое интересное:
При запросе POST данные приходят массивом.
При запросе PUT данные вообще не приходят. Если сделать Content-type: text, то приходит строка запроса.

Может кто-то знает от чего может быть такое поведение?
Как бы заголовки в оба метода идут одинаковые и работать должны одинаково.

Еще при Content-type: application/json и попытке получить данные через Request от Symfony прибегает ошибка: Invalid json message received

.
Hey guys! Finally I'm gonna change status!?
# UJIN (25.07.2017 / 13:53)
При запросе PUT данные вообще не приходят. Если сделать Content-type: text, то приходит строка запроса.
Так ты похоже сам и ответил, значит передаешь не json. Сам $.ajax покажи, или чем ты там PUT передаешь.
.
Добавлено: 26.07.2017 / 12:07
не, я в заголовках прописывал специально Content-type: application/json.. Грит, что невалидный json.
Передаю через postman. Там есть возможность заполнить табличку form-data с параметрами..
Два одинаковых запроса отправляю на POST и PUT. POST обрабатывает, PUT нет. При этом и обработчики у них одинаковые =)

Добавлено: 26.07.2017 / 17:37
текст ошибки (+/-)

{
"error": {
"code": 400,
"message": "Bad Request",
"exception": [
{
"message": "Invalid json message received",
"class": "Symfony\\Component\\HttpKernel\\Exception\\BadRequestHttpException",
"trace": [
{
"namespace": "",
"short_class": "",
"class": "",
"type": "",
"function": "",
"file": "/home/ujin/PhpstormProjects/university/api/structure/vendor/friendsofsymfony/rest-bundle/EventListener/BodyListener.php",
"line": 115,
"args": []
},
{
"namespace": "FOS\\RestBundle\\EventListener",
"short_class": "BodyListener",
"class": "FOS\\RestBundle\\EventListener\\BodyListener",
"type": "->",
"function": "onKernelRequest",
"file": null,
"line": null,
"args": [
[
"object",
"Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent"
],
[
"string",
"kernel.request"
],
[
"object",
"Symfony\\Component\\HttpKernel\\Debug\\TraceableEventDispatcher"
]
]
},
{
"namespace": "",
"short_class": "",
"class": "",
"type": "",
"function": "call_user_func",
"file": "/home/ujin/PhpstormProjects/university/api/structure/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php",
"line": 104,
"args": [
[
"array",
[
[
"object",
"FOS\\RestBundle\\EventListener\\BodyListener"
],
[
"string",
"onKernelRequest"
]
]
],
[
"object",
"Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent"
],
[
"string",
"kernel.request"
],
[
"object",
"Symfony\\Component\\HttpKernel\\Debug\\TraceableEventDispatcher"
]
]
},
{
"namespace": "Symfony\\Component\\EventDispatcher\\Debug",
"short_class": "WrappedListener",
"class": "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener",
"type": "->",
"function": "__invoke",
"file": null,
"line": null,
"args": [
[
"object",
"Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent"
],
[
"string",
"kernel.request"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher"
]
]
},
{
"namespace": "",
"short_class": "",
"class": "",
"type": "",
"function": "call_user_func",
"file": "/home/ujin/PhpstormProjects/university/api/structure/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php",
"line": 212,
"args": [
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent"
],
[
"string",
"kernel.request"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher"
]
]
},
{
"namespace": "Symfony\\Component\\EventDispatcher",
"short_class": "EventDispatcher",
"class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
"type": "->",
"function": "doDispatch",
"file": "/home/ujin/PhpstormProjects/university/api/structure/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php",
"line": 44,
"args": [
[
"array",
[
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
]
]
],
[
"string",
"kernel.request"
],
[
"object",
"Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent"
]
]
},
{
"namespace": "Symfony\\Component\\EventDispatcher",
"short_class": "EventDispatcher",
"class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
"type": "->",
"function": "dispatch",
"file": "/home/ujin/PhpstormProjects/university/api/structure/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php",
"line": 146,
"args": [
[
"string",
"kernel.request"
],
[
"object",
"Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent"
]
]
},
{
"namespace": "Symfony\\Component\\EventDispatcher\\Debug",
"short_class": "TraceableEventDispatcher",
"class": "Symfony\\Component\\EventDispatcher\\Debug\\TraceableEventDispatcher",
"type": "->",
"function": "dispatch",
"file": "/home/ujin/PhpstormProjects/university/api/structure/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php",
"line": 129,
"args": [
[
"string",
"kernel.request"
],
[
"object",
"Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent"
]
]
},
{
"namespace": "Symfony\\Component\\HttpKernel",
"short_class": "HttpKernel",
"class": "Symfony\\Component\\HttpKernel\\HttpKernel",
"type": "->",
"function": "handleRaw",
"file": "/home/ujin/PhpstormProjects/university/api/structure/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php",
"line": 68,
"args": [
[
"object",
"Symfony\\Component\\HttpFoundation\\Request"
],
[
"integer",
1
]
]
},
{
"namespace": "Symfony\\Component\\HttpKernel",
"short_class": "HttpKernel",
"class": "Symfony\\Component\\HttpKernel\\HttpKernel",
"type": "->",
"function": "handle",
"file": "/home/ujin/PhpstormProjects/university/api/structure/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php",
"line": 171,
"args": [
[
"object",
"Symfony\\Component\\HttpFoundation\\Request"
],
[
"integer",
1
],
[
"boolean",
true
]
]
},
{
"namespace": "Symfony\\Component\\HttpKernel",
"short_class": "Kernel",
"class": "Symfony\\Component\\HttpKernel\\Kernel",
"type": "->",
"function": "handle",
"file": "/home/ujin/PhpstormProjects/university/api/structure/web/app_dev.php",
"line": 29,
"args": [
[
"object",
"Symfony\\Component\\HttpFoundation\\Request"
]
]
},
{
"namespace": "",
"short_class": "",
"class": "",
"type": "",
"function": "require",
"file": "/home/ujin/PhpstormProjects/university/api/structure/vendor/symfony/symfony/src/Symfony/Bundle/WebServerBundle/Resources/router.php",
"line": 42,
"args": [
[
"string",
"/home/ujin/PhpstormProjects/university/api/structure/web/app_dev.php"
]
]
}
]
}
]
}
}
.
(\/)____o_O____(\/)

UJIN, огонь лог, как будто все сломалось

.
kantry
Hey guys! Finally I'm gonna change status!?

UJIN, Не знаю как ты post-ом массив получаешь, но включить консоль в браузере и поглядеть что тебе вместо объекта json приходит, надо
У себя пробовал все работает, без разницы какой метод, думаю в симфонии не намного отличается))

$(document).ready(function () {
    $.ajax({
        url: '1.php',
        type: 'PUT',
        data: "name=sender&location=path",
        success: function(data) {
            alert('Load was performed.');
            }
            }
        );
});

Передатчик(1php)
header('Content-type: application/json');
$put = ['sender' => 'UJIN',
        'path' => 'http://johncms.com/'
        ];
$method = ['method' => $_SERVER['REQUEST_METHOD']];
echo json_encode([$method, $put]);
.

да, действительно, аяксом запрос отправлял и все нормально работает
странное поведение постмена
походу, какие-то заголовки не доотправляю

Всего: 6