This article introduces how to HTTP POST data using the Linux curl command and how to escape ampersands (&).
For curl form data POST, two options can be used.
f and d. The difference is that f can only send one key, but d can send multiple parameters.
curl https://example.com/ -X POST -f 'html=hogehogehoge' #=> Ok
curl https://example.com/ -X POST -f 'html=hogehogehoge&fuga=fugafuga' #=> Error
curl https://example.com/ -X POST -d 'html=hogehogehoge' #=> Ok
curl https://example.com/ -X POST -d 'html=hogehogehoge&fuga=fugafuga' #=> Ok
Also, if โ&โ is included in the data, it will be recognized as a separate key after the &, so escaping is necessary.
curl https://example.com/ -X POST -d 'html=hogehogehoge&fugafugafuga'
You can escape and use curl at the same time by doing this:
curl https://example.com/ -X POST --data-urlencode 'html=hogehogehoge&fugafugafuga'
If you want to specify multiple parameters, specify multiple options.
curl https://example.com/ -X POST --data-urlencode 'html=hogehogehoge&fugafugafuga' --data-urlencode 'hoge=hoge'
Or use this script. Bash urlencode and urldecode
urlencode 'hogehogehoge&fugafugafuga'
hogehogehoge%26fugafugafuga
curl https://example.com/ -X POST -d 'html=hogehogehoge%26fugafugafuga'