2013-03-06 56 views
1

我想通過網絡爲Linux機器編寫數據收集器。唉,我不希望我的用戶通過電子郵件提交信息,但也將我的Web服務器當作收件人收集者。我認爲這很容易,但我沒有得到結果。捲曲文件 - > cgi(perl)作爲數據收集器?

說我的客戶端有一個文件「results.txt」,我希望客戶端與我的cgi服務器perl腳本進行通信。我想,如果我的客戶端運行

 
    `$ curl -X POST -d @results.txt http://mycollectorsite/my-collector.pl` 

 
    `$ curl -X GET -d @results.txt http://mycollectorsite/my-collector.pl` 

我應該能看到我的Perl CGI腳本的結果。

腳本運行良好。唉,當我正在查看my-collector.pl在其%ENV和@STDIN中收到的內容時,我發現results.txt文件沒有出現在它中。

很明顯,我在這裏做了一些愚蠢的事情,但是它讓我不知道它是什麼。

[添加代碼示例]

代碼:

+0

results.txt的內容是什麼?它是否與正在發送的MIME類型相匹配? – FatalError 2013-03-06 02:13:06

+2

如果您發佈了代碼,以便我們可以看到它在做什麼,那麼我們將更容易確定您的代碼爲什麼不能做到您想要的。理想情況下,你應該發佈一個最小失敗案例 - 一些足夠完整的東西,我們可以自己運行它,並且長度不超過20-30行(在這種情況下可能更少),這表明問題。 – 2013-03-06 08:45:28

回答

0

我降落在這個古老的,發現的Mac捲曲的手冊頁這個答案。

-F, --form <name=content> 
    (HTTP) This lets curl emulate a filled-in form in which a user has 
    pressed the submit button. This causes curl to POST data using 
    the Content-Type multipart/form-data according to RFC 2388. 

    Example: to send an image to a server, where 'profile' is the name 
    of the form-field to which portrait.jpg will be the input: 

     curl -F [email protected] https://example.com/upload.cgi 

    To read content from stdin instead of a file, use - as the 
    filename. This goes for both @ and < constructs. Unfortunately it 
    does not support reading the file from a named pipe or similar, 
    as it needs the full size before the transfer starts. 

    You can also tell curl what Content-Type to use by using 'type=', 
    in a manner similar to: 

     curl -F "[email protected];type=text/html" example.com 

    or 

     curl -F "name=daniel;type=text/foo" example.com 

那麼什麼工作對我來說發送文本文件(HTML表單字段名稱結果)和一個HTML格式的文本字段(名稱EMAIL_ADDRESS)就像這樣:

curl -F "[email protected];type=text/ascii" -F "[email protected]" http://mycollectorsite/my-collector.cgi 

這是一種形式/ cgi處理導師,可以使用此curl發送命令正常工作:https://www.sitepoint.com/uploading-files-cgi-perl/