I'm using this code to get scandinavian characters posted to php correctly.
我正在使用此代码将斯堪的纳维亚字符正确发布到php。
Issue here is that StandardCharsets.UTF_8 is not supported before API 19
这里的问题是API 19之前不支持StandardCharsets.UTF_8
byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8);
DataOutputStream wr = new DataOutputStream( con.getOutputStream());
wr.write( postData );
Field requires API level 19 (Current min is 14): java.nio.charset.StandardCharsets#UTF_8
字段需要API级别19(当前最小值为14):java.nio.charset.StandardCharsets #UTF_8
How should I do this with API lower than 19?
我应该如何使用低于19的API?
1 个解决方案
#1
43
Use forName static method of Charset class:
使用Charset类的forName静态方法:
byte[] postData = urlParameters.getBytes(Charset.forName("UTF-8"));
List of standard charsets you can find in documentation.
您可以在文档中找到的标准字符集列表。
#1
43
Use forName static method of Charset class:
使用Charset类的forName静态方法:
byte[] postData = urlParameters.getBytes(Charset.forName("UTF-8"));
List of standard charsets you can find in documentation.
您可以在文档中找到的标准字符集列表。