Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I POST LF with curl command line tool?

Tags:

linux

curl

I'm trying to POST to the HTTP gateway of an SMS provider (Sybase 365) using CURL from a Linux shell script.

I need to pass the following data (note the [ ] and LF characters)

[MSISDN]
List=+12345678
[MESSAGE]
Text=Hello
[END]

If I submit a file using the -F parameter, CURL removes the LF e.g.

curl -F @myfile "http://www.sybase.com/..."

results in this at the server (which is rejected)

[MSISDN]List=+12345678[MESSAGE]Text=Hello[END]

Is there anything I can do to avoid this or do I need an alternative tool?

I'm using a file containing my data for testing but I'd like to avoid that in practice and POST directly from the script.

like image 813
Robin Minto Avatar asked Dec 23 '08 07:12

Robin Minto


2 Answers

Try using --data-binary instead of -d(ata-ascii).

From the manual:

--data-binary (HTTP) This posts data in a similar manner as --data-ascii does, although when using this option the entire context of the posted data is kept as-is.

If you want to post a binary file without the strip-newlines feature of the --data-ascii option, this is for you. If this option is used several times, the ones following the first will append data.

ETA: oops, I should read the question more closely. You're using -F, not -d. But --data-binary may be still be worth a shot.

like image 193
Athena Avatar answered Sep 20 '22 17:09

Athena


Probably a silly thought, but I don't suppose it actually requires CRLF instead of just LF?

Alternatively, have you tried using the --data-binary option instead of -F?

like image 31
Jon Skeet Avatar answered Sep 20 '22 17:09

Jon Skeet