简体   繁体   English

无服务器的PHP slim框架POST没有获取发布的数据

[英]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. 我一直在探索无服务器的php,因此选择使用苗条的框架,因为我发现随即将使用的插件模块变得更加容易,而我正在构建的只是以几种形式登录页面。 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. 所以我已经在瘦身框架上制作了登陆页面并让它在像micro实例这样的传统服务器上运行,但是当我使用bref将其迁移到无服务器的php时,但是post方法似乎不再起作用了。

I consume the API I made using slim + bref serverless via AJAX. 我使用通过AJAX使用slim + bref无服务器制作的API。 I passed the contentType : application/json , with a POST method but still not working. 我使用POST方法传递了contentType : application/json ,但仍无法正常工作。

I have used the following methods: 我使用了以下方法:

  1. $request->getParsedBody() -> this works fine on a non-serverless framework. $request->getParsedBody() ->在非无服务器框架上可以正常工作。 But on serverless php bref it went "internal server error" 但在无服务器的php bref上它出现了“内部服务器错误”
  2. $_POST -> works fine locally and traditional servers but on cloudwatch and var_dumping it is empty array. $_POST _POST->在本地和传统服务器上都可以正常工作,但是在cloudwatch和var_dumping上,它是空数组。
  3. $request->getParams() (not working no method of that is existing but I saw it here in Stackoverflow) $request->getParams() (不起作用,不存在该方法,但是我在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. 我发现的解决方法是在GET方法上使用它,但实际上我想使用POST方法,因为我想在密码上使用它。

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. 我将仅更新问题,因为我已经弄清楚了,我正在使用jquery AJAX调用。 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. 我确实使用过contenType:application / json',但当我不使用ajax并只是简单地提交表单,发布的数据出现在cloudwatch上并被转储时,它却无法正常工作。 I guess for some unkown reason it does not work on AJAX(I did try it on postman too,but no luck). 我想因为一些未知的原因它不适用于AJAX(我确实在邮递员上尝试过,但没有运气)。 I even tried the file_get_contents("php://input") to get posted json but still not working. 我甚至尝试使用file_get_contents(“php:// input”)来发布json,但仍然无法正常工作。 Will just stick to page reloading.Thanks again! 只会坚持页面重新加载。再次感谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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