开发者

how does Java url.openStream() work

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜