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.
-
Exact dupe: stackoverflow.com/questions/1359689/…Sam Becker– Sam Becker2010年11月15日 14:36:12 +00:00Commented Nov 15, 2010 at 14:36
-
Tutorial: [How to use java.net.URLConnection to fire and handle HTTP requests? ](stackoverflow.com/questions/2793150/…)BalusC– BalusC2010年11月15日 14:38:57 +00:00Commented Nov 15, 2010 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– Mark Peters2010年11月15日 14:43:14 +00:00Commented Nov 15, 2010 at 14:43
2 Answers 2
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();
//...
Comments
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/