我正在尝试通过网络为linux机器编写数据收集器。唉,我不希望我的用户通过电子邮件提交信息,但也滥用我的网络服务器作为收件人收集者。我认为这很容易,但我没有得到结果。
说我的客户端有一个文件“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 :(得分:0)
我登上了这个旧版本,并在Mac curl的手册页中找到了这个答案。
-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 profile=@portrait.jpg 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 "web=@index.html;type=text/html" example.com
or
curl -F "name=daniel;type=text/foo" example.com
那么对我来说发送文本文件(html表单字段名称结果)和一个html表单文本字段(名称为email_address)的方法是这样的:
curl -F "results=@results.txt;type=text/ascii" -F "email_address=auser@emailservice.com" http://mycollectorsite/my-collector.cgi
这是一个表单/ cgi处理导师,可以使用此curl send命令正常工作:https://www.sitepoint.com/uploading-files-cgi-perl/