2

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?

EDIT: 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;
            }
        });

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

1 Answers1

0

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;}
Udo Held
  • 12,314
  • 11
  • 67
  • 93
Rob
  • 426
  • 8
  • 23