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
SAMLResponse=PZXhXN0iSxR3Lklvbd3dlGjpNaW5hdGlWWxbj0wb20aYyb25zZSB%2bi5jFYWRpdHwMv0vZ28v%0acG5zZT4=

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

curl -XPOST --data @saml.txt http://www.example.net/

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.