如何处理 Volley 中 API 的 HTML 响应
How To Deal With HTML Response from the API in Volley
我在 api 请求响应中获取原始 html 整页数据。我想在 webview 或任何 pdf 查看器中显示它们。已经尝试在 webview 中显示它们,但由于令牌问题对我不起作用。有更好的方法或任何建议来处理这个问题吗?
url = //your url will be here
StringRequest request = new StringRequest(Request.Method.GET, url, (String response) -> {
Log.e("loadData: ",response);
if(response != null){
Response = response;
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
progressDialog.dismiss();
System.out.println("Response" + response);
//webView.loadData(response,"text/html","utf-8");
//webView.loadData(response, "text/html; charset=UTF-8", null);
****//here i used the response to load in a webview!****
webView.loadDataWithBaseURL(null, response, "text/html", "UTF-8", null);
}
},2000);
}
}, error -> {
error.printStackTrace();
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> map = new HashMap<>();
map.put("Authorization", token);
return map;
}
};
RequestQueue queue = Volley.newRequestQueue(RiderPringtinActivity.this);
queue.add(request);
我在 api 请求响应中获取原始 html 整页数据。我想在 webview 或任何 pdf 查看器中显示它们。已经尝试在 webview 中显示它们,但由于令牌问题对我不起作用。有更好的方法或任何建议来处理这个问题吗?
url = //your url will be here
StringRequest request = new StringRequest(Request.Method.GET, url, (String response) -> {
Log.e("loadData: ",response);
if(response != null){
Response = response;
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
progressDialog.dismiss();
System.out.println("Response" + response);
//webView.loadData(response,"text/html","utf-8");
//webView.loadData(response, "text/html; charset=UTF-8", null);
****//here i used the response to load in a webview!****
webView.loadDataWithBaseURL(null, response, "text/html", "UTF-8", null);
}
},2000);
}
}, error -> {
error.printStackTrace();
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> map = new HashMap<>();
map.put("Authorization", token);
return map;
}
};
RequestQueue queue = Volley.newRequestQueue(RiderPringtinActivity.this);
queue.add(request);