从PHP使用排球与JsonObjectRequest时无法获得的参数 [英] Cannot get parameters from PHP when using Volley with JsonObjectRequest

查看:98
本文介绍了从PHP使用排球与JsonObjectRequest时无法获得的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在用的排球框架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 =值

要看到自己试试:     打印的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&param2=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)

这篇关于从PHP使用排球与JsonObjectRequest时无法获得的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆