0

I have a URL like this and the following method

public static void saveContent( String webURL )throws Exception 
{

    URL website = new URL(webURL);
    URLConnection connection = website.openConnection();
    BufferedReader in = new BufferedReader(
                            new InputStreamReader(
                                connection.getInputStream()));

    StringBuilder response = new StringBuilder();
    String inputLine;

    while ((inputLine = in.readLine()) != null) 
        response.append(inputLine);

    in.close();

    System.out.println(response.toString());
}

However, When I want to print web content, it always fetches the source code of the main page(www.google.com).

How can I solve my problem ? Thanks for your help.

3
  • I think you should check your webURL parameter. May be when you call saveContent method passing value of webURL. The value of webURL already set "www.google.com". Commented Oct 13, 2014 at 17:47
  • As a general suggestion, I'd recommend that you take a look at Jsoup. Commented Oct 13, 2014 at 17:48
  • @soewin i checked webURL parameter and it is correct Commented Oct 13, 2014 at 18:53

1 Answer 1

1

I copied yours code to netbeans and it seems to work correctly. I think the problem could lead on content in method argument "webURL". Try run your app on debug mode and look what you've got back there.

Sign up to request clarification or add additional context in comments.

1 Comment

It has to be something with this URL because on my environment it works correctly... I sent to this method statically main page from facebook and I've got a proper result...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.