• 跨平台base64数据传输注意问题


    今天用base64编码传输json串,android端那边始终看不到图片!

    首先发现android端接收的json串长度不一致,仔细研究发现android端接收到的json数据里把服务器数据里的"/"和"+"过滤掉了。

    查看资料发现,之前使用:new BASE64Encoder().encode(bytes)来转byte[]。

    跨平台传输base64编码数据需使用:Base64.encodeBase64URLSafeString(bytes)(方法含义:将二进制数据编码使用URL安全变化的Base64算法但不块输出)。

    Modifier and TypeMethod 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.
  • 相关阅读:
    关于Response.End的亦常
    关于web.config
    本地打印机的设置
    xml的操作
    javascript定义对象的几种简单方法
    WindowsXP下共享无线网络设置步骤
    第四章:使用Rich控件
    第五章母版页
    第八章数据访问概述
    对lock(obj)中的obj的理解
  • 原文地址:https://www.cnblogs.com/tobey/p/4745754.html
Copyright © 2020-2023  润新知