tags:

views:

1212

answers:

3

.NET has HttpWebRequest and WebClient for simulating a browser's requests.

I'd google it, but I'm not sure what keyword to use.

I want to write code that does does HTTP GETs and POSTs, along with cookies, in an applet or local jar and gives me back the response in a text string or some other parseable structure.

+5  A: 

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.

Vinay Sajip
+3  A: 

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;
}
Mitch Wheat
+1  A: 

html unit for me. i can simulate javascript (to a certain extent)

Titi Wangsa bin Damhore
You must be referring to this: http://htmlunit.sourceforge.net/
MatthewMartin