【问题标题】:http request with Volley-api on Android在 Android 上使用 Volley-api 的 http 请求
【发布时间】:2015-09-29 17:29:37
【问题描述】:

我正在尝试向我的本地主机服务器发出 http-post 请求。我遇到的问题是我提出请求时没有得到任何响应。

我正在执行来自片段类的请求:

loginButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Log.i(TAG, " Button clickde");
                fLogin.setCallback(loginButton); //Let's register a callback

               final RequestQueue queue = Volley.newRequestQueue(getActivity().getApplicationContext());
                HashMap<String, String> params = new HashMap<String, String>();
                params.put("token", "AbCdEfGh123456");

                String url = "http://127.0.0.1/create_row.php";
                JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.POST, url,new JSONObject(params), new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        Log.i(TAG, response.toString());
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Log.i(TAG, error.getMessage());
                    }


                });

                fLogin.setFacebookListener(new FacebookLogin.OnFacebookListener() {

                    @Override
                    public void onFacebookLoggedIn(JSONObject parameters) {

                    }
                });
            }

            });

onResponseResponse.ErrorListener 不会打印任何内容。

【问题讨论】:

    标签: java android post android-volley


    【解决方案1】:

    你没有将jsObjRequest添加到队列中,所以请求没有被执行,将其添加到队列中:

        queue.add(jsObjRequest);
    

    请参阅developer.android.com 上的教程。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多