【问题标题】:how can hide Url or value of parameter in android volley?如何在 android volley 中隐藏 Url 或参数值?
【发布时间】:2017-03-26 06:18:47
【问题描述】:

我在我的应用程序中使用Volley 库,一切正常,但是当我发送请求时,我可以看到以下内容

  • 我的服务器的完整网址

  • 参数名称

  • 和其他值。

我还使用 Kali linux 中的 Ettercap 工具对其进行了检查,结果显示相同。我现在的问题是如何向用户隐藏它?

String url ="http://*******.com/login";


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

        @Override
        public void onResponse(String response) {
            Log.d(TAG, "Login Response: " + response.toString());
            hideDialog();

            try {
                JSONObject jObj = new JSONObject(response);
                boolean error = jObj.getBoolean("error");

                // Check for error node in json
                if (!error) {
                    // user successfully logged in
                    // Create login session

                    // Now store the user in SQLite
                    String name = jObj.getString("name");             
                    String email = jObj.getString("email");
                    String api = jObj.getString("apikey");


                } else {
                    // Error in login. Get the error message
                    String errorMsg = jObj.getString("message");
                    Toast.makeText(getApplicationContext(),
                            errorMsg, Toast.LENGTH_LONG).show();
                }
            } catch (JSONException e) {
                // JSON error
                e.printStackTrace();
                Toast.makeText(getApplicationContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
            }

        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e(TAG, "Login Error: " + error.getMessage());
            Toast.makeText(getApplicationContext(),
                    error.getMessage(), Toast.LENGTH_LONG).show();
            hideDialog();
        }
    }) {

        @Override
        protected Map<String, String> getParams() {
            // Posting parameters to login url
            Map<String, String> params = new HashMap<String, String>();
            params.put("email", email);
            params.put("password", password);

            return params;
        }


    };

    // Adding request to request queue
    MyApplication.getInstance().addToRequestQueue(strReq, tag_string_req);
}

这是我在 Kali linux 中调试器和 Ettercap 的结果。

Email: somthings@yahoo.com Pass:somthing INFO:http://****/mypath/login CONTENT:email=somthings@yahoo.com&password=somthing&

【问题讨论】:

  • 将 SSL 与证书固定结合使用。
  • 对哪些用户隐藏这个?用户真的有ettercap吗?
  • 不要将密码放在 URL 上,将其添加到标题或正文中。尽管人们仍然可以查看,但您需要按照 Commonsware 的建议使用 SSL。
  • @Enzokie 他已经在这样做了。
  • @Enzokie 我这样做了,但这对我不起作用。当我发布参数时,我可以看到所有参数及其值。我认为使用 SSl 不是我的问题,因为在连接到服务器之前我可以看到这个参数,这个问题来自我的凌空请求。

标签: java android json android-volley


【解决方案1】:

由于我能够重现该问题,因此我在此考虑 2 个可能的答案:

1 :使用getHeaders() 而不是getParams(),因为这是添加标头值的正确位置。检查下面的示例。

  @Override
   public Map<String, String> getHeaders() throws AuthFailureError {
        Map<String, String> params = new HashMap<String, String>();
        params.put("email", email);
        params.put("password", password);

        return params;
   }

注意: getHeaders()public

2 : 使用JsonObjectRequest 而不是StringRequest,为什么?我猜您期望的是正文值而不是标头值。

JSONObject requestBody = new JSONObject();
           requestBody.put("email", email);
           requestBody.put("password", password);

JsonObjectRequest strReq = new JsonObjectRequest(Request.Method.POST,
            url,requestBody, new Response.Listener<JSONObject>() {

  ... More code here

} ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-30
    • 2020-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-18
    相关资源
    最近更新 更多