什么是“PHP://输入”的Ruby等价物?

时间:2012-04-22 17:19:30

标签: php ruby silverlight

我创建了一个非常简单的PHP文件,它可以完成非常简单的工作,它将图像从Silverlight OutOfBrowser应用程序流式传输到服务器,它在$_GET$_POST变量之间混合,事实上这里是我非常简单的代码,我知道它缺乏安全性,但我还是写了它,以确保我可以通过网络编写文件,并且它上传了多个文件等100%工作。

<?php
 //Gets 
  $myFile = $_GET['FileName'] ? $_GET['FileName'] : "input_stream.txt";
  $openedFile = fopen($myFile, 'w') or die("can't open file");  
  $input = file_get_contents("php://input");            
  fwrite($openedFile, $input);
  fclose($openedFile);

  //Check the mime type of the file (WRONG WAY)
  $mimeType = mime_content_type($myFile);   
  $input = null;    
  $finfo = finfo_open(FILEINFO_MIME_TYPE); 
  $mimeType = finfo_file($finfo, $myFile);
  echo $myFile . 'was uploaded, mime type : ' . $mimeType;
?>

那么有没有简单的Ruby替代方法来获取原始POST数据(这将是来自Silverlight的ByteArray)?

2 个答案:

答案 0 :(得分:1)

您可能希望使用gem进行http访问。这是一个:

https://github.com/jnunemaker/httparty

这个例子看起来像你需要的:

https://github.com/jnunemaker/httparty/blob/master/examples/basic.rb

答案 1 :(得分:0)

如果你在Rails 3上,request.raw_post()就是你要找的。见http://api.rubyonrails.org/classes/ActionDispatch/Request.html#method-i-raw_post

相关问题