Base64 encoding, backslashes


when you encode in base64 and you need to send this encoded data in json format, how to solve this if you get backslashes in encoded string? i guess you need to somehow escape them?

I do this:


And then I do marshal and send data via http.client, but i get error from server. I guess the issue are backslashes.


There should be no backslash in Base64 encoded data…

Base64 on Wikipedia says, that valid characters are 0-9, a-z, A-Z, +, and /.

Aside of that, as you can see on the playground, json.Marshal would escape the backslash for you.

hello, you are right, i was too quick! thank you for help!

i am having some strange issue with base64. If I send pdf or img files i get back from vendor server, 500, name too long.

But what is interesting is that if I send request (the same request) from Postman, than it works.

Then the request is probably not the same…

I dump the request, copy/paste to postman and send:(

Can you tell us how you do the request via go? Show some code?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.