-1

I am trying to send SMS via java using URL connection, when I'm using the url directly in the browser i receive the SMS, however, using java code seems there is an issue when I call the URL..I wonder if using HttpURLConnection will do the job or not?

code as below :

 try{
 String myMobile = "Country code"+user.getMobile();
 String  Url_str = "http://sms.com/Api/.......+ myMobile+;        
 System.out.println(Url_str);
 URL myURL = new URL(Url_str);
 URLConnection myURLConnection = myURL.openConnection();
  myURLConnection.connect();
} 
            catch (MalformedURLException e) { 
                // new URL() failed
            } 
            catch (IOException e) {   
                // openConnection() failed   
            }

        
  • the code you provided doesn't compile. Please share syntactical correct code – Jens May 22 '23 at 13:35
  • BTW: Never catch exceptions without hanlde it. Atleast log them – Jens May 22 '23 at 13:37
  • "there is an issue" is not a valid question for Stackoverlow. What is the error, symptoms? Be specific and provide details. – aled May 22 '23 at 13:46
  • maybe i'm a little bit poor in Eng, I didn't explain well the request, anyways , the issue is that URL doesn't execute when I use the above code, that is the main issue – Haythem Nasri May 22 '23 at 13:48
  • Throws an error? You should be debugging it. As @Jens said always handle exceptions. – aled May 22 '23 at 14:09

1 Answers1

0

I found the solution :)

Just I need to read the URL, I added the below code and it works fine. Thank you all.

BufferedReader br = new BufferedReader(new InputStreamReader( myURLConnection.getInputStream()));