Volley Post请求需要密码的文件

时间:2015-08-07 06:23:31

标签: android android-volley

我在服务器上的prefer目录上设置了一个密码,用户名无法打开并读取该文件。要打开和读取该文件,Web浏览器会提示a请求用户名和密码。如何在Volley Post Params中设置用户名和密码?

StringRequest sr = new StringRequest(Method.POST,url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {

                    pages = PageParser.parse(response);
                    adapter = new DailyReportAdapter(MenuDailyReport.this,
                            pages);
                    lv.setAdapter(adapter);
                    pDialog.hide();

                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    // error.printStackTrace();
                    pDialog.hide();
                    Toast.makeText(MenuDailyReport.this,
                            "Could not connect to server"+error.getMessage(), Toast.LENGTH_LONG)
                            .show();
                    finish();
                }
            })
    {

            @Override
            protected Map<String,String> getParams(){
                Map<String,String> params = new HashMap<String, String>();

                params.put("username","mohammad" );
                params.put("password","mohammad123" );
                return params;
            }

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

1 个答案:

答案 0 :(得分:-1)

创建HashMap并从getParams()

返回该 protected Map<String, String> getParams() throws com.android.volley.AuthFailureError { Map params = new HashMap<String, String>(); params.put("username", userName); params.put("password", password); return params; };
SELECT n.ID, n.NAme, n.Cat_Id, CAT_NAME
FROM Name n
INNER JOIN Category c
ON n.ID=c.ID ORDER BY c.NAme ASC;