Hello everyone...
I'm using Laravel 5.2 to develop an API for my iOS Application and I have a problem with my POST requests.
Everytime I make a POST request from the app, I receive a GET request in Laravel and so I have a GET response.
For example, in my route:
/users GET //return list of users
/users POST //store new user
When using Postman to make a POST request to the route I get the proper response, of the new user created. But when using my app I get the GET response.
Using another app in my iOS device to make HTTP Requests I also have a good response on POST requests.
I'm trying to figure it out why my app request is being interpreted differently by Laravel, maybe I need to provide another information in my request?
It's obviously your app that don't deliver a proper POST request. You should probably ask on a forum made for iOS devs, I think you will have better luck there.
mengidd said:
It's obviously your app that don't deliver a proper POST request. You should probably ask on a forum made for iOS devs, I think you will have better luck there.
Actually what I'm trying to understand is what Laravel needs to interpret a request as POST.
Because I'm pretty sure that my app is making a POST request, obviously not a good one, so to fix that I wanted to provide all the information in the request.
Knowing that I can then bind a proper POST request from my app, giving no margin to interpret as a different request.
No idea how Laravel handles request, but one way to see if your app is correctly sending a post request is to hit a page where you return $_SERVER['REQUEST_METHOD']. If it's POST this is a Laravel problem, if it's not it's your app :-)
mengidd said:
No idea how Laravel handles request, but one way to see if your app is correctly sending a post request is to hit a page where you return $_SERVER['REQUEST_METHOD']. If it's POST this is a Laravel problem, if it's not it's your app :-)
I did as you said. I created a php file in my public folder:
post.php
<?php
/**
* Created by PhpStorm.
* User: renato
* Date: 06/01/16
* Time: 18:13
*/
$method = $_SERVER['REQUEST_METHOD'];
$json = json_encode(['response' => $method], true);
echo $json;
When I tried accessing post.php with my app it returned
{ response = POST; }
I'm losing my mind here... I really don't know what the problem is...
Turned out to be a problem with the trailing slash. It was 301 redirecting my post requests to a get request.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community