Equivalent of .NET's WebClient and HttpWebRequest in Java?
HttpURLConnection
is Java's equivalent of HttpWebRequest
.
URL iurl = new URL(url);
HttpURLConnection uc = (HttpURLConnection)iurl.openConnection();
uc.connect();
if (uc.getContentType().equalsIgnoreCase("image/jpeg"))
{
result = true;
}
Apache HTTPClient has equivalent functionality, though the APIs are not exactly the same. Oakland Software has a table comparing their commercial product with various alternatives, including the Apache product. Apache's own opinion of the built-in HttpUrlConnection (quoted from the above linked-to page) is:
The jdk has the HttpUrlConnection which is limited and in many ways flawed.
Here's a link to the HTTPClient tutorial.