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
In your Java program, you can use a String containing this text to create a URL object: URL myURL = new URL("http://example.com/"); The URL object created above represents an absolute URL. An absolute URL contains all of the information necessary to reach the resource in question.
openConnection. Returns a URLConnection instance that represents a connection to the remote object referred to by the URL . A new instance of URLConnection is created every time when invoking the URLStreamHandler. openConnection(URL) method of the protocol handler for this URL.
connect method is called. When you do this you are initializing a communication link between your Java program and the URL over the network. For example, the following code opens a connection to the site example.com : try { URL myURL = new URL("http://example.com/"); URLConnection myURLConnection = myURL.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With