Cuthbert
Cuthbert

Reputation: 2998

Java HTTP request message

In Java, how can I construct an HTTP request message to get a resource specified by a request URI that a user inputs after I've opened up a socket to connect with a server?

If anyone could just point me to an article with the general tools I would need, that would be cool too. Thank you!

Upvotes: 1

Views: 1480

Answers (2)

Greg Hewgill
Greg Hewgill

Reputation: 993461

The best low-level reference is the HTTP/1.1 Specification, which describes in detail all possible aspects of an HTTP request message.

If you're not actually interested in building the request yourself, the java.net.URL class contains everything you need.

Upvotes: 1

stivlo
stivlo

Reputation: 85506

You can use Apache HttpClient, in particular HttpGet:

HttpGet httpGet = new HttpGet(url);
ResponseHandler<String> handler = new BasicResponseHandler();
responseBody = httpClient.execute(httpGet, handler);

Upvotes: 1

Related Questions