Problem with URL connection (Sending SMS via URL)

50 views Asked by At

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   
            }

        
1

There are 1 answers

0
Haythem Nasri On

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()));