views:

81

answers:

1

Hello,

This works:

 curl  --url http://someurl.tld  --form "apikey=39485730"

This does not:

 curl  --url http://someurl.tld  --form "apikey=<keyfile"

Error: Invalid API keys

The cURL manual (http://curl.haxx.se/docs/manpage.html) explicitly states

-F/--form (HTTP) This lets curl emulate a filled-in form in which a user has pressed the submit button. [...] To force the 'content' part to be a file, prefix the file name with an @ sign. To just get the content part from a file, prefix the file name with the symbol <. The difference between @ and < is then that @ makes a file get attached in the post as a file upload, while the < makes a text field and just get the contents for that text field from a file.


FWIW: If I use --form "apikey=@keyfile" I get the error: "API key is required". This confirms that @ is definately wrong (which I am okay with). But why does < not work, and what to do about it?

It looks as if the content of the file is either not passed on, or wrong. Thus I've made quadruple sure, that only the api key (here: 39485730) and nothing else is in the file.


If it's important why I am trying to do this:
I need this curl-command in scripts, and don't want to put the API key there. Instead, it should be in the HOME of the user who runs this script, only readable by him, and nobody else.

Thank you in advance for any insight... :-)

+1  A: 

I think you might have a trailing newline in keyfile. You can check this with:

xxd keyfile

There should be no 0a at the end. If there is, you can re-create the keyfile without the trailing newline like this:

echo -n 39485730 > keyfile

and try again with the new keyfile.

Mika Fischer
YES!! Although I tried hard with vim *not* to enter one, alas, there it was. Thanks a bunch!! (And on top: xxd is a nice command; I've been using the awkward hexdump, but xxs is *nice*).
Yes, it is unfortunately rather complicated to avoid this trailing newline with vim. See http://stackoverflow.com/questions/1050640/vim-disable-automatic-newline-at-end-of-file
Mika Fischer