2013-07-29 25 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