当前位置:  开发笔记 > 编程语言 > 正文

Android排球 - 获取响应标题和阅读HTML

如何解决《Android排球-获取响应标题和阅读HTML》经验,为你挑选了1个好方法。



1> Krish..:

为此目的使用自定义请求类,

public class CustomStringRequest extends Request {


    private Response.Listener mListener;

    public CustomStringRequest(int method, String url, Response.Listener responseListener, Response.ErrorListener listener) {
        super(method, url, listener);
        this.mListener = responseListener;
    }


    @Override
    protected void deliverResponse(ResponseM response) {
        this.mListener.onResponse(response);
    }

    @Override
    protected Response parseNetworkResponse(NetworkResponse response) {
        String parsed;
        try {
            parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        } catch (UnsupportedEncodingException e) {
            parsed = new String(response.data);
        }

        ResponseM responseM = new ResponseM();
        responseM.headers = response.headers;
        responseM.response = parsed;

        return Response.success(responseM, HttpHeaderParser.parseCacheHeaders(response));
    }


    public static class ResponseM {
        Map headers;
        String response;
    }

}

并改变这样的代码,

CustomStringRequest stringRequest = new CustomStringRequest(Request.Method.GET, loginURL,
                new Response.Listener() {
                    @Override
                    public void onResponse(CustomStringRequest.ResponseM result) {

                        //From here you will get headers
                        String sessionId = result.headers.get("Set-Cookie");
                        String responseString = result.response;

                    }


                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(LoginActivity.this,error.toString(),Toast.LENGTH_LONG ).show();
                    }
                }) {


        };

推荐阅读
sx-March23
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有