[ACCEPTED]-Strange Base64 encode/decode problem-base64
Whatever populates params
expects the request 6 to be a URL-encoded form (specifically, application/x-www-form-urlencoded
, where 5 "+" means space), but you didn't URL-encode 4 it. I don't know what functions your language 3 provides, but in pseudo code, queryString
should be 2 constructed from
concat(uri_escape("data"), "=", uri_escape(base64_encode(rawBytes)))
which simplifies to
concat("data=", uri_escape(base64_encode(rawBytes)))
The "+
" characters 1 will be replaced with "%2B
".
You have to use a special base64encode which 5 is also url-safe. The problem is that standard 4 base64encode includes +
, /
and =
characters 3 which are replaced by the percent-encoded 2 version.
http://en.wikipedia.org/wiki/Base64#URL_applications
I'm using the following code in 1 php:
/**
* Custom base64 encoding. Replace unsafe url chars
*
* @param string $val
* @return string
*/
static function base64_url_encode($val) {
return strtr(base64_encode($val), '+/=', '-_,');
}
/**
* Custom base64 decode. Replace custom url safe values with normal
* base64 characters before decoding.
*
* @param string $val
* @return string
*/
static function base64_url_decode($val) {
return base64_decode(strtr($val, '-_,', '+/='));
}
Because it is a parameter to a POST you 1 must URL encode the data.
paraquote from the wikipedia link
The encoding 7 used by default is based on a very early 6 version of the general URI percent-encoding 5 rules, with a number of modifications 4 such as newline normalization and replacing spaces 3 with "+" instead of "%20"
another hidden 2 pitfall everyday web developers like myself 1 know little about
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.