简体   繁体   English

使用Android Volley的HTTPS请求

[英]HTTPS request using Android Volley

I am trying to make an HTTPS request via POST with volley but it is not working. 我正在尝试通过齐射通过POST发出HTTPS请求,但是它不起作用。 The request takes me to onErrorResponse but does not show what the error is. 该请求将我带到onErrorResponse,但未显示错误是什么。 I tested with Postman and it works fine. 我与Postman进行了测试,效果很好。 I leave part of my code. 我保留了部分代码。

    Map<String, String> params = new HashMap<String, String>();

    params.put(PARAM_HASH_TOKEN, HASH_TOKEN);
    params.put(PARAM_USUARIO, id);
    params.put(PARAM_PASSWORD, password);

    JSONObject jsonBody = new JSONObject(params);
    Log.e("POST",jsonBody.toString());

    JsonObjectRequest mJsonObjectRequest = new JsonObjectRequest(Request.Method.POST, URL_API, jsonBody, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            if (response != null) {
                F_PARSEAR_JSON_RESPUESTA(response);
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            String msg = (error.getMessage() == null) ? "Ha ocurrido un error, intentelo de nuevo." : error.getMessage();
            Log.e("ERROR",URL_API);
            Log.e("ERROR",msg);               
            _loginButton.setEnabled(true);
        }
    });
    ApplicationLoader.getInstance().addToRequestQueue(mJsonObjectRequest);

Can you check Content type in client and server? 您可以检查客户端和服务器中的内容类型吗? They are similar value. 它们是相似的值。

        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> headers = new HashMap<String, String>();
            headers.put("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
            return headers;
        }
        @Override
        public String getBodyContentType()
        {
            return "application/json";
        }

I hope it will help you! 希望对您有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM