I appreciate if someone could help
GET method works fine but POST method don’t.
I used slim 3 and slim skeleton, the api is on my web page (Cpanel I´m not use localhost)
I have in src/middleware.php the following:
$app->add(function ($req, $res, $next) {
$response = $next($req, $res);
return $response
->withHeader('Access-Control-Allow-Origin', '*')
->withHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization')
->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
});
in src/routes I have:
use Slim\Http\Request;
use Slim\Http\Response;
use Slim\App;
$app->options('/{routes:.+}', function ($request, $response, $args) {
return $response;
});// fim do $app->options('/{
// *******************Routes***********************
require __DIR__ . '/routes/tanahoras.php';
// Catch-all route to serve a 404 Not Found page if none of the routes match
// NOTE: make sure this route is defined last
$app->map(['GET', 'POST', 'PUT', 'DELETE', 'PATCH'], '/{routes:.+}', function ($req, $res) {
$handler = $this->notFoundHandler; // handle using the default Slim page not found handler
return $handler($req, $res);
});// fim do $app->map(['GET',
in the route ‘/routes/tanahoras.php’; I have:
$this->post('/tanahoras/adiciona', function (Request $request, Response $response) {
$dados = $request->getParsedBody()['ProdutoNome'];
$produto = Tanahora::create($dados);
return $response->withJson($produto);
});