跨平台base64数据传输注意问题
今天用base64编码传输json串,android端那边始终看不到图片!
首先发现android端接收的json串长度不一致,仔细研究发现android端接收到的json数据里把服务器数据里的"/"和"+"过滤掉了。
查看资料发现,之前使用:new BASE64Encoder().encode(bytes)来转byte[]。
跨平台传输base64编码数据需使用:Base64.encodeBase64URLSafeString(bytes)(方法含义:将二进制数据编码使用URL安全变化的Base64算法但不块输出)。
Modifier and Type | Method and Description |
---|---|
static byte[] |
decodeBase64(byte[] base64Data)
Decodes Base64 data into octets
|
static byte[] |
decodeBase64(String base64String)
Decodes a Base64 String into octets
|
static BigInteger |
decodeInteger(byte[] pArray)
Decodes a byte64-encoded integer according to crypto standards such as W3C's XML-Signature
|
static byte[] |
encodeBase64(byte[] binaryData)
Encodes binary data using the base64 algorithm but does not chunk the output.
|
static byte[] |
encodeBase64(byte[] binaryData, boolean isChunked)
Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
|
static byte[] |
encodeBase64(byte[] binaryData, boolean isChunked, boolean urlSafe)
Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
|
static byte[] |
encodeBase64(byte[] binaryData, boolean isChunked, boolean urlSafe, int maxResultSize)
Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
|
static byte[] |
encodeBase64Chunked(byte[] binaryData)
Encodes binary data using the base64 algorithm and chunks the encoded output into 76 character blocks
|
static String |
encodeBase64String(byte[] binaryData)
Encodes binary data using the base64 algorithm but does not chunk the output.
|
static byte[] |
encodeBase64URLSafe(byte[] binaryData)
Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output.
|
static String |
encodeBase64URLSafeString(byte[] binaryData)
Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output.
|
static byte[] |
encodeInteger(BigInteger bigInt)
Encodes to a byte64-encoded integer according to crypto standards such as W3C's XML-Signature
|
static boolean |
isArrayByteBase64(byte[] arrayOctet)
Deprecated.
1.5 Use
isBase64(byte[]) , will be removed in 2.0. |
static boolean |
isBase64(byte octet)
Returns whether or not the
octet is in the base 64 alphabet. |
static boolean |
isBase64(byte[] arrayOctet)
Tests a given byte array to see if it contains only valid characters within the Base64 alphabet.
|
static boolean |
isBase64(String base64)
Tests a given String to see if it contains only valid characters within the Base64 alphabet.
|
protected boolean |
isInAlphabet(byte octet)
Returns whether or not the
octet is in the Base64 alphabet. |
boolean |
isUrlSafe()
Returns our current encode mode.
|
作者:唐 冰(Tobey) (http://www.cnblogs.com/tobey/)
版权声明:本文的版权归作者与博客园共同所有。转载时请在明显地方注明本文的详细链接,未经作者同意请不要删除此段声明,感谢您为保护知识产权做出的贡献。