How to send HTTP request to the Web Service

Hi, I am trying this code to send a HTTP Request to a Web Service to check whether the WebService is up or not at a given URL:

***********************

String requestUrl= "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL";
           
            try {
           
                  URL url = new URL(requestUrl.toString());
           
                 
                         HttpURLConnection aConnection = (HttpURLConnection) url.openConnection();
      BufferedReader buffer = new BufferedReader(new InputStreamReader(aConnection.getInputStream()));

                       String line = "";
                       while ((line = buffer.readLine()) != null)
                                                   {
                           System.out.println(line);
                       }

********************
But when I run the code, I get this exception:

java.net.UnknownHostException: www.w3schools.com

I can access this WSDL by typing the url in my explorer which means I have the connectivity to this URL. Any help on this, please?

Thanks
LeoKrisAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
check your browsers proxy settings and use them when you run your app

http://helpdesk.objects.com.au/java/how-to-tell-a-java-application-to-use-a-proxy-server
0
 
LeoKrisAuthor Commented:
There is no proxy setting in my internet explorer..it is not "checked" and there is no script configured too.
0
 
CEHJCommented:
Perhaps you have DNS problems. Try

String requestUrl= "http://216.128.29.26/webservices/tempconvert.asmx?WSDL";
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
LeoKrisAuthor Commented:
oh..thanks for pointing that out.. I will try and let you know.
0
 
LeoKrisAuthor Commented:
strange thing happened... I tried the same code in IntelliJ IDEA and it works like magic... it works with the dns name i.e. www.w3schools.com.

Don't know what is the difference between the IDEs.

Anyway, thanks a lot CEHJ.
0
 
objectsCommented:
Could be a problem with then Network settings in the IDE
Or just a tempoeaey network glitch
0
 
objectsConnect With a Mentor Commented:
The code itself is fine
0
 
CEHJCommented:
Has the original problem disappeared too, or is it still there?
0
 
LeoKrisAuthor Commented:
The original problem is still there, The other IDE I am using is eclipse but in a different laptop. Something to do with Network settings probably.
0
 
LeoKrisAuthor Commented:
Thanks for pointing in the right direction.
0
 
CEHJCommented:
>>Something to do with Network settings probably.

I'm wondering why you've accepted an answer if the problem remains undiagnosed ..?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.