2010-01-18 72 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