无法使用齐射将params发送到服务器

时间:2016-05-01 10:10:25

标签: php android android-volley params

我不知道为什么我不能使用凌空向服务器发送params,我的问题是当我尝试使用velley发送params我将此错误发送到我的logcat时,

[149] BasicNetwork.performRequest: Unexpected response code 403 for http://localhost/test/post.php

每个人都可以帮我解决这个问题吗?

我的php服务器:

<?php
if (isset($_POST['action'])){
    $action = $_POST['action'];
} else {
    echo "Invalid Data";
exit;
}
if($action="read"){
    echo "read";
}
?>

我的要求:

    String  tag_string_req = "string_req";

    String url = "http://localhost/test/post.php";


    StringRequest strReq = new StringRequest(Request.Method.POST,
            url, new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            Log.d("TAG", response.toString());
            Log.d("LOG", "success");

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            VolleyLog.d("TAG", "Error: " + error.getMessage());
        }
    }){
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> params = new HashMap<String, String>();
            params.put("action", "read");
            return params;
        }
    };
    AppController.getInstance().addToRequestQueue(strReq, tag_string_req);

1 个答案:

答案 0 :(得分:0)

我认为问题是您的网址参数。 “localhost”是与设备本身连接的单词,您的服务器无法在其上运行。  而不是localhost,您需要编写运行服务器的计算机的IP。

示例:“http://replace_it_with_the_ip/test/post.php”;

相关问题