android - 如何在 Volley 中处理来自 API 的 HTML 响应
问题描述
我在我的 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);
推荐阅读
- node.js - 无法使用 mlab-mongodb 向远程数据库发出 post 请求?
- algorithm - 二维数组中的总水容量,表示地形图
- c# - Xamarin 表单在 Toggle [Android] 上切换 IsToggled 绑定 NRE
- sql - Adding an apostrophe into a dynamic SQL
- gstreamer - 可以使用 multifilesink 保存带有时间戳的 jpegenc 图像
- java - Java 优化 - 局部变量与对象属性
- swift - 使用 ARKit 将画廊中的图像放在墙上
- html - IE11 中的 SVG 蒙版比例和缩放
- python-2.7 - 打开要追加的文件
- c++ - 这个 declval 的定义基于什么 C++ 规则?