【问题标题】:curl a file -> cgi (perl) as data collector?卷曲文件-> cgi (perl) 作为数据收集器?
【发布时间】:2013-02-20 16:07:54
【问题描述】:

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

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

[添加代码示例]

代码:

【问题讨论】:

  • results.txt的内容是什么?它是否与正在发送的 MIME 类型匹配?
  • 如果您发布代码,我们将更容易确定为什么您的代码没有执行您想要的操作,这样我们就可以看到它在做什么。理想情况下,您应该发布一个最小的失败案例——它足够完整,我们可以自己运行它,并且长度不超过 20-30 行(在这种情况下可能更少),这表明了问题。

标签: perl post cgi


【解决方案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/

【讨论】:

    猜你喜欢
    • 2015-04-09
    • 1970-01-01
    • 1970-01-01
    • 2013-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多