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.

asked Nov 15, 2010 at 14:34
3
  • Exact dupe: stackoverflow.com/questions/1359689/… Commented Nov 15, 2010 at 14:36
  • Tutorial: [How to use java.net.URLConnection to fire and handle HTTP requests? ](stackoverflow.com/questions/2793150/…) Commented 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. Commented Nov 15, 2010 at 14:43

2 Answers 2

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();
//...
answered Nov 15, 2010 at 14:36
Sign up to request clarification or add additional context in comments.

Comments

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/

answered Nov 15, 2010 at 14:38

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.