首页 > 解决方案 > Android Volley 在服务器上没有被识别为 POST 与 php

问题描述

我正在使用 volley 将帖子发送到我的服务器。在我的 php 里面 insert.php 我有这样的代码

if($_SERVER['REQUEST_METHOD'] == 'POST'){

   //do all post functions
}
 else{
//notofication that says its not post

}

这是我的 android 中的凌空代码

String HttpUrl = "http://192.168.30.18/insert.php";

    // Creating string request with post method
    StringRequest stringRequest = new StringRequest(Request.Method.POST, HttpUrl,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String ServerResponse) {

                    // Hiding the progress dialog after all task complete.
                    progressDialog.dismiss();

                    // Showing response message coming from server.
                    Toast.makeText(CreateAccountOrLoginActivity.this, ServerResponse, Toast.LENGTH_LONG).show();
                    Log.d("responseSuccess",ServerResponse);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {

                    // Hiding the progress dialog after all task complete.
                    progressDialog.dismiss();

                    // Showing error message if something goes wrong.
                    Toast.makeText(CreateAccountOrLoginActivity.this, volleyError.toString(), Toast.LENGTH_LONG).show();
                    Log.d("responseFail",volleyError.toString());
                }
            }) {

        @Override
        protected Map<String, String> getParams() {



            // Creating Map String Params.
            Map<String, String> params = new HashMap<String, String>();

            // Adding All values to Params.
            params.put("title",title);
            params.put("name", fname);
            params.put("surname", sname);
           


            return params;
        }

    };

    // Creating RequestQueue.
    RequestQueue requestQueue = Volley.newRequestQueue(CreateAccountOrLoginActivity.this);

    // Adding the StringRequest object into requestQueue.
    requestQueue.add(stringRequest);

问题是在运行 android 代码后,它返回 insert.php 的 else 语句中的内容,而不是 if 语句中的内容,这意味着它不会被识别为帖子。我如何解决它以使其在 if 语句中运行

标签: javaphpandroidandroid-volley

解决方案


推荐阅读