将JSON字符串从Android Studio发送到PHP

I want to send a JSON string from Android Studio to PHP.

I'm currently using the code from this youtube tutorial.

This was the code provided

final String server_url="http://192.168.0.23:81/volley/test.php?";


StringRequest stringRequest=new StringRequest(Request.Method.POST, server_url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response)
                    {
                        Log.d("response", "result : "+response); //when response come i will log it
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error)
                    {
                        error.printStackTrace();
                        error.getMessage(); // when error come i will log it
                        Log.d("ERROR", error.getMessage());
                    }
                }
        )
        {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {

                Map<String,String> param=new HashMap<String, String>();
                param.put("array", new Gson().toJson(dataList)); // array is key which we will use on server side
                param.put("hello", "hi");

                return param;
            }


        };

        stringRequest.setShouldCache(false);
        Vconnection.getnInstance(this).addRequestQue(stringRequest);

and this is the Vconnection file:

    private static Vconnection nInstance;
    private RequestQueue RQ;
    private Context CTX;

    private Vconnection(Context context)
    {
        CTX=context;
        RQ=getRequestQue();
    }

    public RequestQueue getRequestQue()
    {
        if(RQ==null)
        {
            RQ= Volley.newRequestQueue(CTX.getApplicationContext());
        }
        return RQ;
    }
    public static synchronized Vconnection getnInstance(Context context)
    {
        if(nInstance==null)
        {
            nInstance=new Vconnection(context);
        }
        return nInstance;
    }
    public <T> void addRequestQue(Request<T> request)
    {
        RQ.add(request);
    }

I think this code works because it returns the JSON string as a result in the onResponse function in the Logcat part of Android Studio but I'm confused as to why it shows

"Undefined index: array in C:\xampp\htdocs\volley\test.php on line 3"

when I load the server_url.

Any help would be much appreciated. Thank you!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐