dongshen6060 2016-05-01 02:10
浏览 34
已采纳

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

i don't know why i cant send params to server using volley , my problem is when i'm trying to use velley to send params i get this error to my logcat,

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

can every one help me to solve this problem ?

my php server :

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

my request :

    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条回答 默认 最新

  • dongpankao6133 2017-04-26 11:26
    关注

    I think the problem is your URL parameter. "localhost" is a word that connecting with the device itself, and your server can't run on it. instead of localhost, you need to write the IP of the computer that running the server.

    example: "http://replace_it_with_the_ip/test/post.php";

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部