6

Possible Duplicates:
How to send HTTP request in java?
How to use java.net.URLConnection to fire and handle HTTP requests?

using java, how do i hit any url?

for instance, opening of http://www.xyz.com/node1 in a browser will tell xyz.com that node1 is hit. so in this java program (which sends sms text say 'node1' in example above embedded in the url itself to a sms gateway server)

how do i achieve it without opening any browser or using servlet.

Community
  • 1
  • 1
aksci
  • 150
  • 1
  • 2
  • 10
  • Exact dupe: http://stackoverflow.com/questions/1359689/how-to-send-http-request-in-java – Sam Becker Nov 15 '10 at 14:36
  • Tutorial: [How to use java.net.URLConnection to fire and handle HTTP requests? ](http://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests) – BalusC Nov 15 '10 at 14:38
  • 1
    @Sam152: That's a completely different question, dealing with sending an HTTP request. That's different than just loading a URL. – Mark Peters Nov 15 '10 at 14:43

2 Answers2

6

You can use an HttpURLConnection.

But using it directly is overkill if you just want to load the URL in question. This guide shows you how to open a URL.

Basically it boils down to:

URL url = new URL("http://www.xyz.com/node1");
URLConnection conn = url.openConnection();
conn.connect();
//...
Mark Peters
  • 80,126
  • 17
  • 159
  • 190
0

The simplest way is to use URL http://download.oracle.com/javase/1.4.2/docs/api/java/net/URL.html. For more advanced/flexible URL fetching you could use HttpClient http://hc.apache.org/httpclient-3.x/

Richard H
  • 38,037
  • 37
  • 111
  • 138