2010-01-18 68 views
0

这工作:卷曲--form文件重定向

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

这不:

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

错误: 无效的API密钥

卷曲手册(http://curl.haxx.se/docs/manpage.html)明确规定

-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: 如果我使用--form“apikey = @ keyfile”,我得到错误:“API密钥是必需的”。 这证实了@肯定是错误的(我很好)。 但为什么<不工作,怎么办呢?

它看起来就像该文件的内容或者未通过的,还是错。因此,我做了四重确认,只有api键(这里是:39485730),没有其他文件在文件中。


如果它是重要的,为什么我试图做到这一点:
我需要在脚本这个卷曲命令,不想把API密钥那里。相反,它应该在运行此脚本的用户的HOME中,只能由他读取,而不能由其他人读取。

预先感谢您的任何见解... :-)

+0

我相信你的问题将是对堆栈溢出更好。 – alex 2010-01-19 07:09:43

回答

2

我想你可能有一个换行符在keyfile。你可以检查这个:

xxd keyfile 

最后应该没有0a。如果有,你可以不喜欢这个结尾的换行重新创建密钥文件:

echo -n 39485730 > keyfile 

,并用新keyfile再试一次。

+0

是的!尽管我很努力地用vim * not *来输入一个,唉,那就是它了。感谢一堆! (最重要的是:xxd是一个很好的命令;我一直在使用笨拙的hexdump,但是xxs是* nice *)。 – 2010-01-19 17:00:09

+0

是的,不幸的是,避免使用vim这个尾随的换行符非常复杂。请参阅http://stackoverflow.com/questions/1050640/vim-disable-automatic-newline-at-end-of-file – 2010-01-19 19:27:10