Solved

How to send HTTP request to the Web Service

Posted on 2009-05-09
11
565 Views
Last Modified: 2013-11-19
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
0
Comment
Question by:LeoKris
  • 5
  • 3
  • 3
11 Comments
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
Comment Utility
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
 

Author Comment

by:LeoKris
Comment Utility
There is no proxy setting in my internet explorer..it is not "checked" and there is no script configured too.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Perhaps you have DNS problems. Try

String requestUrl= "http://216.128.29.26/webservices/tempconvert.asmx?WSDL";
0
 

Author Comment

by:LeoKris
Comment Utility
oh..thanks for pointing that out.. I will try and let you know.
0
 

Author Comment

by:LeoKris
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 92

Expert Comment

by:objects
Comment Utility
Could be a problem with then Network settings in the IDE
Or just a tempoeaey network glitch
0
 
LVL 92

Assisted Solution

by:objects
objects earned 250 total points
Comment Utility
The code itself is fine
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Has the original problem disappeared too, or is it still there?
0
 

Author Comment

by:LeoKris
Comment Utility
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
 

Author Closing Comment

by:LeoKris
Comment Utility
Thanks for pointing in the right direction.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
>>Something to do with Network settings probably.

I'm wondering why you've accepted an answer if the problem remains undiagnosed ..?
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now