0

I'm trying to run a URL command that suppose to call from my software to a phone, and it's working is just that I want it without the browser OR with it and close it after like 3-5 seconds it's also fine by me. So basically there is String contains: URL + phone number now I tried a lot of options like:

    HttpURLConnection httpConn = null;
    URL url = new URL(url_open);
    httpConn = (HttpURLConnection) url.openConnection();

    httpConn.setRequestMethod("GET");
    // Time out after a 5 seconds
    httpConn.setConnectTimeout(5000);
    httpConn.connect();
    httpConn.disconnect();

And I tried:

Process p = Runtime.getRuntime().exec("C:\\Program Files\\Internet 
Explorer\\iexplore.exe" +" " + url_open);
Thread.sleep(5000);
System.out.println("The address" + " " + url_open);
p.destroy();

Without success.

Cœur
  • 32,421
  • 21
  • 173
  • 232
  • FYI: You will never need to run a `Process` to get something done. And when you will need one, then you made a mistake ;) – AxelH May 08 '18 at 06:21
  • Possible duplicate of [How to use java.net.URLConnection to fire and handle HTTP requests](https://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests) – AxelH May 08 '18 at 06:21

1 Answers1

0

Please try the following code:

        String url = "<Your URL>";      
        URL obj = new URL(url);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
        con.setRequestMethod("GET");
        //add request header
        con.setRequestProperty("User-Agent", "Mozilla/5.0");
        int responseCode = con.getResponseCode();

        if(responseCode == 200){
              System.out.println("Done!!");     
         }
Santosh
  • 16,973
  • 4
  • 50
  • 75