1

我正在尝试通过网络为 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 文件没有出现在其中。

显然,我在这里做了一些愚蠢的事情,但它让我无法理解它是什么。

[添加代码示例]

代码:

4

1 回答 1

1

我登陆了这个旧版本,并在 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 发送命令:https ://www.sitepoint.com/uploading-files-cgi-perl/

于 2016-11-01T15:27:01.903 回答