简体   繁体   中英

Serverless PHP slim framework POST does not get posted data

I have been exploring serverless php for and I opted on using slim framework because I find it easier to just plugin modules as I go and that what I am building is just landing pages with a few forms. So I have made the landing pages on slim framework and had it working on traditional servers like micro instances but when I migrated it on serverless php specifically using bref but the post method does not seem to work anymore.

I consume the API I made using slim + bref serverless via AJAX. I passed the contentType : application/json , with a POST method but still not working.

I have used the following methods:

  1. $request->getParsedBody() -> this works fine on a non-serverless framework. But on serverless php bref it went "internal server error"
  2. $_POST -> works fine locally and traditional servers but on cloudwatch and var_dumping it is empty array.
  3. $request->getParams() (not working no method of that is existing but I saw it here in Stackoverflow)

The work around I found was to have it on GET method but I actually want to use POST method because I'd like to use it on passwords.

Anyone who has experienced the same?

Thanks

I will just update the question because I just figured it out, I was using jquery AJAX call. I did use contenType :application/json' but it is not working BUT when I did not use ajax and just simply submit the form, the posted data appeared on cloudwatch and got dumped. I guess for some unkown reason it does not work on AJAX(I did try it on postman too,but no luck). I even tried the file_get_contents("php://input") to get posted json but still not working. Will just stick to page reloading.Thanks again!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM