【发布时间】:2016-04-15 21:12:18
【问题描述】:
我有一个应用程序,我在其中使用短信提供商将短信发送到我的安卓设备。 我正在发送以下形式的消息:
message = "value: "+Float.toString(float1)+" and ratio: "+Float.toString(float2)
我正在使用 jva.net 库,代码是:
System.out.println("Sending sms");
InputStream response = null;
URLConnection connection = null;
try {
connection = new URL("https://somesmsprovider.com/sms/sms.jsp?user=user&password=pass&mobiles=xxxxxxxxxx&sms="+message).openConnection();
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
但是,我在设备上收到的只是:“值:”
我猜这与编码有关。提供者可以选择激活 unicode 编码,但这也无济于事。 有人知道为什么我无法正确显示短信吗?
谢谢
【问题讨论】:
-
我们可以有完整的代码吗?
-
我想这是导致问题的结果 URL 中的空格。尝试将它们替换为
%20-message = message.replace(" ", "%20");。 -
嗨,迈克,没错,谢谢!!!如果您发表评论,我会标记它作为答案。