今天用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 |
static boolean |
isBase64(byte octet)
Returns whether or not the |
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 |
boolean |
isUrlSafe()
Returns our current encode mode. |