我有一个应用程序,在这里我使用短信提供程序将短信发送到我的android设备。我正在发送以下形式的消息:
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编码,但这都没有帮助。有人知道为什么我无法正确显示短信吗?
Thnks
显然,结果URL中的空格引起了问题。只需用百分比编码的值替换它们%20
-似乎可以解决问题。
message = message.replace(" ", "%20");
如果您在邮件中包含除字母数字和基本标点符号之外的任何字符,则可能需要对整个进行URL编码String
。该URLEncoder
班是在Android中使用,虽然它编码空格作为+
,所以你可能要进行replace()
编码后,类似上述情况,我会想象+
会经历不变在邮件正文中。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句