我使用下面的代码打开一个文件但不起作用,并显示消息“BasicNetwork.performRequest:http:// .....的意外响应代码401”。 android和排球有什么问题?
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;
}
;
};
答案 0 :(得分:0)
问题可能是charset,必须是utf-8,我想。所以
尝试覆盖此方法,覆盖覆盖getheaders()内部,因为它:
@Override
public String getBodyContentType() {
return "application/x-www-form-urlencoded; charset=UTF-8";
}
我建议使用Bearer Token作为标题,更好。 问候。