dongwei1263 2016-01-22 02:09
浏览 38

使用Android Volley将数据发布到网址无效

I want to post some data to a url, then get the posted data from that url and store it in a database. I've tried to echo the posted params but they appear not to have been posted and no error is shown. Below is the function I use to do the post:

public void insertDataWithVolley() {
        String url = "http://apps.example.com/application/index.php/main/getParamsFromVolley";
        RequestQueue requestQueue = Volley.newRequestQueue(this);
        StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Toast.makeText(getApplicationContext(), response,
                        Toast.LENGTH_LONG).show();
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(getApplicationContext(), error.getMessage(),
                        Toast.LENGTH_LONG).show();

            }
        }) {
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> mapObject = new HashMap<>();
                mapObject.put("id", "ID");
                Log.d("TAG", "Put id");
                mapObject.put("name", "NAME");
                Log.d("TAG", "Put name");
                return mapObject;
            }
        };
        requestQueue.add(stringRequest);
    }

On the PHP side, this is the function, see below:

public function getParamsFromVolley() {
        $id = null;
        $name = null;

        if (isset($_GET['id'])) {
            $id= $this->input->get('id');
        }
        if (isset($_GET['name'])) {
            $name= $this->input->get('name');
        }
        //store $pesapal_tracking_id in your database against the order with orderid = $reference09
        echo 'name>>>>' . $id; 
        echo 'email>>>>' . $name;               

        //return $pesapal_tracking_id;
    }

Kindly assist

  • 写回答

1条回答 默认 最新

  • dongyao1895 2016-01-22 02:53
    关注

    I don't know PHP but you are checking GET in PHP while your are making POST request in Volley. Change PHP code to check POST params.

        if (isset($_POST['id'])) {
            $id= $this->input->get('id');
        }
        if (isset($_POST['name'])) {
            $name= $this->input->get('name');
        }
    

    Also make a simple html page to check if your post request is working after the change.

    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大