2016-11-11 26 views
1

我用Volley庫在我的應用程序,一切正常,但是當我發送一個請求,我可以看到我的服務器的以下如何隱藏Url或android volley中的參數值?

  • 完整URL的參數

  • 名稱

  • 和其他值。

我也在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中的debuger和Ettercap的結果。

Email: [email protected] Pass:somthing INFO:http://****/mypath/login CONTENT:[email protected]&password=somthing& 
+0

使用帶證書固定的SSL。 – CommonsWare

+0

從什麼用戶隱藏這個?用戶真的有'ettercap'嗎? – EJP

+0

不要把密碼放在URL上,而是將它添加到標題或正文中。雖然人們仍然可以看到,所以你需要使用SSL作爲Commonsware的建議。 – Enzokie

回答

-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 

} ...