Volley POST 请求接收错误结果

Volley POST Request receiving wrong results

我已经在在线服务器上托管了我的 API。当我使用 chrome 的 Postman 应用程序对其进行测试时,它 return 给我正确的结果(即来自数据库的用户的详细信息)但是下面的 Volley 请求得到了错误的结果(即. 缺少必需的参数);

Postman 请求的屏幕截图

截击请求

private void loginUser(final String username, final String password){

        String URL_REGISTER = "http://www.h8pathak.orgfree.com/jobs/login.php";
        pDialog.setMessage("Logging in...");
        showDialog();


        StringRequest strReq = new StringRequest(Request.Method.POST,
                URL_REGISTER, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                hideDialog();
                try {
                    JSONObject jObj = new JSONObject(response);
                    int result = jObj.getInt("result");


                    if(result==1){

                        session.setLogin(true);

                        JSONObject jObj2 = jObj.getJSONObject("user");
                        Intent i = new Intent(LoginActivity.this, EmployerActivity.class);
                        i.putExtra("username", jObj2.getString("username"));
                        i.putExtra("email", jObj2.getString("email"));
                        startActivity(i);
                        finish();
                        Toast.makeText(LoginActivity.this, jObj.getString("message"), Toast.LENGTH_SHORT).show();
                    }

                    else{
                        Toast.makeText(LoginActivity.this, jObj.getString("message"),Toast.LENGTH_SHORT).show();

                    }
                }

                catch (JSONException e) {
                    e.printStackTrace();
                }

            }

        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                Toast.makeText(LoginActivity.this, volleyError.getMessage(), Toast.LENGTH_SHORT).show();
                hideDialog();
            }
        }){

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

                Map<String, String> params = new HashMap<>();
                params.put("username", username);
                params.put("password", password);

                return params;
            }
        };

        AppController.getInstance().addToRequestQueue(strReq);

    }

PHP代码接收请求参数和return适当的响应。

if(isset($_POST['username']) && isset($_POST['password']))  {

    $username = $_POST['username'];
    $password = $_POST['password'];

      //Get the details from the database and echo in a json response

}

else{

    $message = "Required parameters missing!";
    $response['result']=0;
    $response['message']=$message;

    echo json_encode($response);
}   

可能的错误是什么?

您的服务器配置有问题:http://www.h8pathak... 未按预期响应,但 http://h8pathak... 有效。后者在您的邮递员示例中使用,在您的 Android 代码中使用它,它也可以在那里工作。

WWW 就是答案。这一定是一个错误。它转到 URL 并运行它但不运行 POST。

http://www.example.com/myphpfile.php 错误。

http://example.com/myphpfile.php是对的。