我需要從Volley響應中獲取重定向url:在我的情況中,最後一次重定向url返回404,但我無法弄清楚如何從VolleyError
獲取url。Android Volley獲取重定向url
0
A
回答
0
設計您的服務器後,在發送一個響應返回給客戶端時添加URL在標題可以從VolleyError獲得頭
NetworkResponse response = volleyError.networkResponse;
if (response != null && response.data != null) {
Map<String, String> headers = response.headers;
String URL = headers.get("my_url_key");
}
或者交替,每次你做一些要求,您可以在此改變getHeaders()
例如
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET,
createURL(), null, success, errorListener) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> header = new HashMap<>();
header.put("my_url_key", "http://mywebsite.com");
return header;
}
};
檢索是一樣的,上面的代碼,但方便多了,因爲你將不再需要在你的服務器進行任何更改。
如果要執行基於響應代碼,你可以做以下的重定向:
NetworkResponse response = volleyError.networkResponse;
if (response != null && response.data != null) {
if(response.statusCode == 404){
// Do something here
}
}
讓我們只是希望服務器將包括與二元響應沿重定向URL。
Ex。
NetworkResponse response = volleyError.networkResponse;
if (response != null && response.data != null) {
JSONObject o = new JSONObject(new String(response.data));
// get the info here
}
相關問題
- 1. Android - 獲取url重定向
- 2. Google Volley Imageloader - 取消302重定向請求或攔截重定向url
- 3. PHP獲取重定向URL
- 4. 獲取重定向URL
- 5. 重定向url獲取直接url
- 6. 獲取重定向的Android
- 7. android url重定向
- 8. 獲取URL的一部分重定向
- 9. curl被重定向後獲取url
- 10. 從url重定向獲取html內容
- 11. JS - 如何獲取重定向的URL
- 12. PL/SQL代碼獲取重定向URL
- 13. 如何獲取重定向的URL
- 14. PHP:獲取url後重定向
- 15. 獲取重定向的url PowerShell for webcrawler
- 16. .getScript獲取javascript的重定向url
- 17. 使用cURL獲取重定向URL
- 18. 獲取URL重定向後,從JavaScript
- 19. Jmeter - 從重定向URL獲取參數
- 20. 在javascript中獲取iframe重定向url
- 21. Google Closure - XhrIO:獲取重定向URL
- 22. 在urllib2中獲取重定向的url
- 23. scrapy - 獲取最終重定向的URL
- 24. 從URL獲取參數並重定向?
- 25. 在perl中獲取重定向url
- 26. AJAX - 重定向後獲取響應URL
- 27. 獲取URL重定向地方從
- 28. 使用Java獲取重定向URL org.apache.http.client
- 29. 如何獲取OkHttp3重定向的URL?
- 30. Erlang:ibrowse - 獲取重定向的URL
看到http://stackoverflow.com/questions/32630993/android-volleyerror-retrieve-requested-url volleyerror對象 –
檢查從Web服務的響應頭,看它是否具有「位置」值或不?你可以嘗試使用郵遞員等工具嗎? – BNK