curl with base64 encoded data

I just spent the last hour trying to figure out how to send base64 encoded data that lives in a file using curl. Everyone says to just use --data-binary but that assumes you know what the binary format should actually be! Every combination I tried of --data-ascii and --crlf kept failing with server-side errors.

The trick for me was making sure that the file itself was manually URL encoded. So all newlines were replaced with %0a and all plus signs were replaced with %2b. Then just put everything on one line. So my file (which was a SAML payload for testing) looked like:

                                                                 +                     \n

This can just be sent using the normal --data parameter as a file:

curl -XPOST --data @saml.txt

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.