2013-07-29 27 views
0

我尝试使用WoT Dossier服务的档案转换成JSON的关键,而在他们的FAQ,它们显示出以下卷曲例如:发布与卷曲一个文件,但不知道在POST

curl --data-binary @dossier.dat http://wot-dossier.appspot.com/service/dossier-to-json 

经过几个小时的摸索,我发现有什么问题,我没有运气。下面的代码我使用(PHP)尝试复制命令:

$url = "http://wot-dossier.appspot.com/service/dossier-to-json"; 

$file = realpath('dossier_temp/' . $full_fn); 

echo $file; 

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/octet-stream")); 
curl_setopt($ch, CURLOPT_POSTFIELDS, array("@$file")); 

$curl_res = curl_exec($ch); 

curl_close($ch); 

$json = json_decode($curl_res, true); 

A中的JSON的var_dump()显示NULL,但是这怎么可能呢?在某个地方的postfield中是否有错误?

任何帮助,将不胜感激

回答

1

不包括在postfields一个数组,试试这个。看来你的文章只需要成为一个原始的数据流。

$data = file_get_contents($file); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
+0

如果你曾经在附近,我会给你买一瓶啤酒。干杯。 – Timr