tags:

views:

37

answers:

1

I have used the Java command url.openStream() many times to retrieve data from the web. However, I don't have any idea what it's doing. Does it go through my browser, does it establish a separate port, or what?

I would like to know how this works so I can determine how the command would play through an internet anonymizer.

If anyone has any insights on this, I'd sure appreciate hearing them.

Thanks

A: 

Calling url.openStream() initiates a new TCP connection to the server that the URL resolves to. An HTTP GET request is then sent over the connection. If all goes right (i.e., 200 OK), the server sends back the HTTP response message that carries the data payload that is served up at the specified URL. You then need to read the bytes from the InputStream that the openStream() method returns in order to retrieve the data payload into your program.

Note: The request does not go through your browser. It is executed by a Java class that acts as an HTTP client running in your JVM.