Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my code.

private String get()
   {

       String response = "";
       try
       {

           URL connectURL = new URL("http://localhost:8182/lightControlPage/statusAll");
           HttpURLConnection conn = (HttpURLConnection)connectURL.openConnection();
           // do some setup
           conn.setDoInput(true);
           conn.setDoOutput(true);
           conn.setUseCaches(false);
           conn.setRequestMethod("GET");
           // connect and flush the request out
           conn.connect();
           conn.getOutputStream().flush();
           // now fetch the results
           response = getResponse(conn);
           Displaymsg(response);
           }
           catch(Exception ex)
           {
               return ex.getMessage();
           }
       return response;
       //return response;
     }
private String getResponse(HttpURLConnection conn)
   {
       InputStream is = null;
       try
       {
           is = conn.getInputStream();
          return is.toString();
       }
       catch(Exception e)
       {
       }
       finally
       {
       }

       return is.toString();
   }



This result in unknown protocol localhost, and when i change localhost to http:// valid ip address it returns null. when i do it from the browser it works as it gives a string in return in json format. Any help?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900