Solution to the error message "invalid base-64 character array length" during deserialization

Source: Internet
Author: User

ProgramTo serialize an object and pass it as a parameter to another page. This page gets the parameter and returns it after deserialization, but sometimes it works normally at runtime, sometimes the error message "invalid base-64 character array length" appears.

Searching for information on the Internet means convert is used. when the tobase64string () method is used to encode a string using base64, the parameter length must be equal to an even multiple of 4 or 4. Otherwise, a "formatexception" exception is thrown. However, the parameters I used here are generated using the convert. tobase64string () method, which is theoretically correct. Therefore, convert is used for comparison. string a generated by tobase64string () and convert before deserialization. the parameter string B used by tobase64string () is found to be different between A and B, and the plus sign in a is changed to a space. This is because when a webpage passes a parameter, the plus sign is encoded into a space, but the space is not decoded during decoding. As a result, string B is incorrect and cannot be encoded.

Once the problem is confirmed, the serialization string is used. replace ("+", "% 2B") First encodes the space and then passes it as a parameter to another page for transmission, in this way, the page decodes "% 2B" as the plus sign only when extracting parameters. There are no differences in parameters, and the deserialization succeeds.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.