Could not submit form-data through postman put request

扶醉桌前 提交于 2019-12-24 01:17:47

问题


I m using lumen api 5.6. This is my route $router->PUT('collections/{collectionId}' In postman i m calling this api like this.

and this is the body of that request

See here i have CollectioPoints here but its failing in validation. the data i m sending through formdata is not able to recognized in validation.

But if i send the route from put to post [$router->POST('collections/{collectionId}'], all the data i m sending through form data are recognized and i m getting correct response as below

Why this is happening. Cant i send form data through put request? Thaank you.


回答1:


Laravel(Lumen) cheats because html forms only support GET and POST, but it does understand a real PUT/PATCH request.

In Postman You should send POST and set _method to PUT (same as sending forms) to make your data and files visible

 _method = "PUT"

Or

If you don't have any file only have data then you can write you parameter in choose below option in Postman

 x-www-form-urlencode 

Or

You want use PUT method for send Data with form-Data option you should use stuff like this https://gist.github.com/devmycloud/df28012101fbc55d8de1737762b70348




回答2:


Example

Headers: Content-Type application/x-www-form-urlencoded

_method = "PUT"

an your controller

return $request->file('avatar');

image example



来源:https://stackoverflow.com/questions/51302049/could-not-submit-form-data-through-postman-put-request

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!