![](/img/trans.png)
[英]Android Volley - Getting No Response using StringRequest to XML API
[英]Getting AuthFailure Error when using StringRequest using Volley
我按如下方式發送 Volley StringRequest
StringRequest getRequest = new StringRequest(Request.Method.GET, myUrl,
new Response.Listener<String>()
{
@Override
public void onResponse(String response) {
try {
if (response!=null)
{
//do some work
}
}
catch (Exception e)
{
Log.d("error",e.getMessage());
}
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
Log.d("error",error.toString());
}
}
) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
String token = "",cookie="";
token = getSharedPreferences(getResources().
getString(R.string.pref_login_data), Context.MODE_PRIVATE)
.getString("login_token","");
cookie = "token="+token+";";
Map<String, String> param = new HashMap<String, String>();
param.put("api-key", myAPIKey);
param.put("Cookie", cookie);
return param;
}
};
Volley.newRequestQueue(this).add(getRequest);
每次調用 onErrorResponse 並給出 AuthFailure 錯誤
但是當我在郵遞員中使用相同的標題點擊相同的網址時,它會起作用並且返回json字符串,郵遞員的屏幕截圖如下:
我正在努力解決這個問題超過 3 天,任何幫助將不勝感激
僅將 Request.Method.GET 更改為 Request.Method.POST。
因為你是通過POST方式發送參數,但是你使用了Get方式!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.