Envoyer des SMS vers un mobile en utilisant Java(Tiers-Site2SMS)
J'ai écrit le code suivant dans JAVA
pour envoyer un SMS à un appareil mobile en utilisant le service Web gratuit de la région de l'Inde Site2SMS site. Je m'authentifie via une clé en utilisant l'api Mashape .
Soo voici mon code et erreur MSG.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class SendSMS
{
static String SMSApi = "https://site2sms.p.mashape.com/index.php?msg=Hello&phone=0987654321&pwd=abcdef&uid=XXXXXXXXXX";
static String head = "XXXXXXXXXXXXXXXX";
public static void main(String[] args)
{
try
{
String url = SMSApi;
String smsApiResponse = sendMySMS(url);
System.out.println(smsApiResponse);
}
catch (Exception e)
{
e.printStackTrace();
}
}
private static String sendMySMS(String url)
{
StringBuilder output = new StringBuilder();
try
{
URL hp = new URL(url);
System.out.println(url);
URLConnection hpCon = hp.openConnection();
hpCon.setRequestProperty("X-Mashape-Key", head);
BufferedReader in = new BufferedReader(new InputStreamReader(hpCon.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
output.append(inputLine);
in.close();
}
catch (Exception e)
{
e.printStackTrace();
}
return output.toString();
}
}
Lorsque j'exécute le code, j'obtiens la réponse d'erreur suivante:
java.io.IOException: Server returned HTTP response code: 403 for URL: https://site2sms.p.mashape.com/index.php?msg=Hello&phone=0987654321&pwd=abcdef&uid=1234567890
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
at SendSMS.sendMySMS(SendSMS.java:33)
at SendSMS.main(SendSMS.java:15)
(La clé Mashape
, stockée dans head
et le uid
dans l'URL du message sont obscurcis.)
Quelqu'un peut-il aidez-moi à comprendre ce qui ne va pas et comment corriger mon code?
0
Author: Jason R. Mick, 2017-03-08