【问题标题】:How To Deal With HTML Response from the API in Volley如何在 Volley 中处理来自 API 的 HTML 响应
【发布时间】:2021-03-30 15:24:00
【问题描述】:

我在我的 api 请求响应中获得了原始的 html 完整页面数据。我想在 webview 或任何 pdf 查看器中显示它们。已经尝试在 webview 中显示它们,但由于令牌问题对我不起作用。有什么更好的方法或任何建议来处理这个问题?

【问题讨论】:

  • 比什么好?你没有提供你的方式......也要求“更好”是基于意见
  • @Selvin 刚刚编辑。请检查。谢谢

标签: android html api android-volley


【解决方案1】:
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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-26
    • 2018-06-06
    • 2019-04-25
    • 1970-01-01
    • 2013-08-27
    相关资源
    最近更新 更多