2

When I connect() to a URL. Is Java fetching the webpage as a browser would, just without displaying it?

I'm trying to understand for example, if I were to connect to a Youtube Video URL. Even though i could not see the page, is the URL Connection loading the page and playing the video as if from a typical browser (without the UI or visual representation of the page)?

user3813948
  • 291
  • 2
  • 12
  • 1
    It might help to learn how HTTP works in general. – Nick Humrich Jul 07 '14 at 20:52
  • It is very unlikely that this is happening. There is more to playing a Youtube video than fetching some HTML. You need a flash component or something equivalent to actually handle the video stream. I would indeed recommend catching up on web requests in general... – Kris Jul 07 '14 at 21:05
  • possible duplicate of [Can you explain the HttpURLConnection connection process?](http://stackoverflow.com/questions/10116961/can-you-explain-the-httpurlconnection-connection-process) – Kris Jul 07 '14 at 21:06

2 Answers2

2

It is fetching the raw HTML of the web page. Similar if you where to open a page in your browser and right click->View Source.

If you connect to a Youtube page, you will get the raw HTML and within that code, will be a reference (href), most likely a tag that points to the source of the video.

--Edit

A browser then obviously interprets that HTML into what you see on your screen. A modern browser automatically connects to all references on that HTML page, as if loading multiple pages simultaneously, and putting them together.

Nick Humrich
  • 12,894
  • 8
  • 56
  • 80
tier1
  • 5,797
  • 6
  • 41
  • 69
2

No, the URLConnection represents only that, a URL connection. Using UrlConnection.openConnection() is connecting to the page, but it still needs to be told what to do. It will provide you with a "printing" of the elements on the page only if told to do so. However, it has accessed that file. Connecting to and reading information from a page is a multistep process.

Please see the Oracle Java Documentation about URLConnections. It provides a lot more information and clarity into how this class works as well as how to use it.

http://docs.oracle.com/javase/7/docs/api/java/net/URLConnection.html

abalos
  • 1,161
  • 6
  • 12