我现在用的排球框架JsonObjectRequest请求。我使用
JsonObjectRequest loginRequest =新JsonObjectRequest(b.toString(),参数,可以
新的监听器和LT;的JSONObject>(){},
新Response.ErrorListener(){});
在 PARAMS
变量包含的参数,它是一个JSONObject的。
现在的问题是,我不能访问这些变量在我的PHP code。 $ _ POST或$ _REQUEST变量给我什么。
我也试过类似下面,但没有运气。
$数据= json_de code(的file_get_contents(PHP://输入));
解决方案
我在使用乱射与我的PHP API遇到了同样的确切的问题!事实证明,使用PARAMS中的JSONObject沿着JSON格式发送。因此,PHP $ _ POST将无法识别它,因为它是不是在格式:参数1 =值1&放大器;参数2 =值
![如何同时运行多个不同版本的php网站,一键解决](https://p.xsw88.cn/allimgs/daicuo/20230905/1874.png)
要看到自己试试: 打印的file_get_contents(PHP://输入);
我写了一个博客文章有关这一点,并提出了解决方法的类。而不是使用JsonObjectRequest中,我创建请求的一个子类(第4节)
I am using the Volley framework with JsonObjectRequest request. I am using
JsonObjectRequest loginRequest = new JsonObjectRequest(b.toString(), params,
new Listener<JSONObject>() {},
new Response.ErrorListener() {});
The params
variable contains the parameters and it is a JSONObject.
The problem is that I cannot access any of these variables in my PHP code. $_POST or $_REQUEST variables gives me nothing.
I also tried something like below but no luck.
$data = json_decode(file_get_contents("php://input"));
解决方案
I encountered the same exact problem while using Volley with my PHP API! Turns out, using JSONObject of params is sent along as JSON. Therefore, PHP $_POST won't recognize it because it isn't in the format: param1=value1¶m2=value
To see for yourself try: print file_get_contents("php://input");
I wrote a blog post about this and made a workaround class. Instead of using JsonObjectRequest, I created a subclass of Request (Section 4)
相关推荐
最新文章