开发者

curl --form file redirection

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 th开发者_运维百科e 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... :-)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜