0

Can anybody tell me how to write a java client code to call restful web service with one parameter say email? I am trying the below code. But I am getting response as Success. Once this is success, I need the below XPHONE value. How to get this value?

XPHONE: 52-33-3669-7000 

Here is the client code:

URL url = new URL("http://bluepages.ibm.com/BpHttpApisv3/wsapi?byInternetAddr=user.email");
                        HttpURLConnection conn = (HttpURLConnection) url
                                .openConnection();
                        conn.setRequestMethod("GET");
                        conn.setReadTimeout(15000);
                        conn.setConnectTimeout(15000);
                        conn.setRequestProperty("Accept",
                                "application/json");
                        conn.connect();
Iamat8
  • 3,888
  • 9
  • 25
  • 35
Rajyalakshmi S
  • 173
  • 1
  • 4
  • 16
  • if the response is in json format you can use the json library http://www.oracle.com/technetwork/articles/java/json-1973242.html otherwise you can parse the string – Petter Friberg Oct 08 '15 at 12:23

3 Answers3

0

I think you just missing response body handling.

There is nice article about rest-client code: article.

nukie
  • 691
  • 7
  • 14
0

You can try using the JavaLite Http client:

JavaLite Http

Myzreal
  • 351
  • 4
  • 16
0

Depends on how API is implemented value can be in response body or even in header, so this info you should know from specification or ask in dev team.

First try to check if everything works fine using CURL or better "Advanced rest client" ( its extension in Chrome browser) if it works, than just transfer flow to your code. How to use advanced rest client look here

Community
  • 1
  • 1
Shell Scott
  • 1,679
  • 18
  • 28