HttpClient的使用的WebView [英] HttpClient with WebView

查看:86
本文介绍了HttpClient的使用的WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是HttpClient的显示使用loadDataWithBaseURL web视图的网页。我的网站有一些链接,我想,当用户点击该链接就可以继续使用的HttpClient。是否有可能呢?
在这种情况下,当用户点击链接,我必须拦截的链接,这样,我的浏览器将加载它,然后停止加载并使用HTTPGET。听起来是不是足够合理?

I am using an httpclient to display a web page in the webView using loadDataWithBaseURL. My web site has some links and I want to continue using httpClient when user clicks on the link. Is it possible to do? In this case when user clicks on the link i must intercept the link, so that my browser will load it, then stop loading it and use HttpGet. Does it sound reasonable enough?

编辑:
是啊,这是个好主意..
首先您设置一个客户端

Yup, that was a good idea.. firstly you set a client

comments.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url){

                String LinkTag = "";
                try {
                    LinkTag = client.httpGet(url);
                } catch (ClientProtocolException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (URISyntaxException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                comments.loadDataWithBaseURL("BaseWebUrl", LinkTag, "text/html", "utf-8", "");
                return true;
            }
        });

其次,你必须创建一个HttpClient的处理您的文章和获取也许其他方法,以及

And secondly you must create an httpClient to handle your Posts and Gets and maybe other methods as well

推荐答案

您需要做的就是你所谓后 HttpClient的HC =新DefaultHttpClient(); 设置它作为第一个活动或者类中的公共静态变量,你在使用它。然后,当用户点击一个链接,你必须调用HTTPGET你只设置新的HttpClient了newName = originalClass.hc ; ,这将存储您的cookies

What you need to do is after you call HttpClient hc = new DefaultHttpClient(); is set it as a public static variable in the first activity or class that you are using it in. Then when the user clicks on a link and you have to call HttpGet you will just set the new HttpClient newName = originalClass.hc; and this will store your cookies.

public class FirstClass{  
   public static HttpClient hc = new DefaultClient();
   {make the original get call}

public class NewClass{
    //new httpclient
    {HttpClient newHC = FirstClass.hc;}

这篇关于HttpClient的使用的WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆