Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Sinch(Android)发送短信息_Android_Sinch - Fatal编程技术网

使用Sinch(Android)发送短信息

使用Sinch(Android)发送短信息,android,sinch,Android,Sinch,我正在尝试使用Sinch发送短信,但我从服务器收到404和500个错误 我阅读了Sinch文档,我的代码与示例相匹配。有什么东西不见了吗 你可以在下面看到我的代码。当我试图读取输入流时,它崩溃了 public static boolean sendSMS(String message) { try { String phoneNumber = "00351961234567"; URL url = new URL("https:

我正在尝试使用Sinch发送短信,但我从服务器收到404和500个错误

我阅读了Sinch文档,我的代码与示例相匹配。有什么东西不见了吗

你可以在下面看到我的代码。当我试图读取输入流时,它崩溃了

 public static boolean sendSMS(String message) {

        try {
            String phoneNumber = "00351961234567";
            URL url = new URL("https://messagingapi.sinch.com/v1/sms/ " + phoneNumber);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoOutput(true);
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "application/json");
            String userCredentials = "application\\" + Constants.SINCH_APP_KEY + ":" + Constants.SINCH_APP_SECRET;

            byte[] encoded = Base64.encodeBase64(userCredentials.getBytes());
            String basicAuth = "Basic " + new String(encoded);
            connection.setRequestProperty("Authorization", basicAuth);

            String postData = "{\"From\":\"00351913470050\" \"Message\":\"" + message + "\"}";
            OutputStream os = connection.getOutputStream();
            os.write(postData.getBytes());
            int status = connection.getResponseCode();

            StringBuilder response = new StringBuilder();
            InputStreamReader is = new InputStreamReader(connection.getInputStream());
            BufferedReader br = new BufferedReader(is);
            String line;
            while ( (line = br.readLine()) != null)
                response.append(line);
            br.close();
            os.close();

            Log.i("SMS", response.toString());

            return true;
        } catch (IOException e) {
            e.printStackTrace();
        }

        return false;
    }

我们支持的所有国家现在都被列入了白名单。在Android Studio上,在“InputStreamReader is=new InputStreamReader(connection.getInputStream());”行中,您不应该有这个问题,它会生成异常文件NotFoundException您可以发布处理错误的消息吗?有时这些更具体,可能很简单,因为你的帐户上没有任何钱可以发送短信。我收到{“errorCode”:40001,“message”:“国家代码PT不是用于发送短信的白名单”}。我给Sinch support发送了一封电子邮件,因为在他们的网站上,他们支持葡萄牙通信,所以让我们等待它现在工作吧?是的,正在工作!谢谢你,杰恩森希,杰恩森!只有91(沃达丰PT)的号码再次出现问题。我给Sinch Support发送了一封电子邮件。打电话时,听筒电话不响