tags:

views:

777

answers:

3

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.

+2  A: 

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?

Jon Skeet
CRLF or LF - it doesn't make any difference - but until you and Athena made me aware of --data-binary, I couldn't send either. Thanks.
Robin M
+4  A: 

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.

Athena
That's the conclusion I'd just come to as well :)
Jon Skeet
Aha! I'd been working from this page http://curl.haxx.se/docs/manual.html which I've just realised is just usage - it doesn't mention --data-binary. I actually want to avoid using -F because I want to avoid using the filesystem.
Robin M
+1  A: 

I've got this working using -d

request=`printf "[MSISDN]\nList=$number\n[MESSAGE]\nText=$message\n[END]\n"`
response=`curl -s -u $username:$password -d "$request" http://www.sybase.com/...`

Curiously, if I use -d @myfile (where myfile contains LF separated text), it doesn't work.

I also tried --data-binary without success.

Robin M