1

I learned from this post that I can use entity codes for characters like @ = %40 & = %26 but I can't find how to include a %.

For example, I want to do the below command but it errors because of the %. Is there a way to escape it?

curl -d 'name=foo&description=bar has a 25% discount' http://localhost:3000/api/v1/products
Community
  • 1
  • 1
diasks2
  • 2,033
  • 2
  • 36
  • 61

2 Answers2

1

% = %25

This tool was helpful in discovering how to encode it: http://meyerweb.com/eric/tools/dencoder/ which does the following in JavaScript:

 function encode() {
   var obj = document.getElementById('dencoder');
   var unencoded = obj.value;
   obj.value = encodeURIComponent(unencoded).replace(/'/g,"%27").replace(/"/g,"%22");   
 }
diasks2
  • 2,033
  • 2
  • 36
  • 61
1

Anything encoded should be %[two-digit hexadecimal of its byte value], which makes '%' to encode to %25.

curl also features the command line option --data-urlencode to help with this.

Daniel Stenberg
  • 54,736
  • 17
  • 146
  • 222