1

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!

Cuthbert
  • 2,908
  • 5
  • 33
  • 60
  • Related: http://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests – BalusC Sep 30 '11 at 03:23

2 Answers2

1

You can use Apache HttpClient, in particular HttpGet:

HttpGet httpGet = new HttpGet(url);
ResponseHandler<String> handler = new BasicResponseHandler();
responseBody = httpClient.execute(httpGet, handler);
stivlo
  • 83,644
  • 31
  • 142
  • 199
1

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.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • The low level reference was what I was looking for. Your other link will help me out in the future. Thanks! – Cuthbert Sep 30 '11 at 04:25