2015-01-08 37 views
2

我嘗試轉換以下的curl命令:轉換一個curl命令到PHP代碼捲曲(文件傳輸和自定義命令)

curl --digest --user "username:password" --verbose --url "http://127.0.0.1/ws?graph-uri=http://localhost/dataset/import/" -X POST -T /data/datasets/foo.n3 

這裏是一個似乎是好的代碼,但不工作:

$args = array(); 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1/ws?graph-uri=http://localhost/dataset/import/'); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); 
curl_setopt($ch, CURLOPT_USERPWD, "username:password"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($ch, CURLOPT_HEADER, true); 
curl_setopt($ch, CURLOPT_VERBOSE, true); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); 
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true); 
$args['graph-uri'] = curl_file_create('/data/datasets/foo.n3'); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $args); 
$result = curl_exec($ch); 

看來這個文件實際上是與PHP代碼上傳,但到處看的curl_file_create()的使用似乎不錯。

+0

在添加cURLFile對象之前,$ args是什麼? –

+0

@CharlotteDunois剛剛編輯的問題,使其明確。基本上:一個空陣列。 – Neoasimov

+0

我很想看看處理這個請求的代碼。 –

回答

0

嘗試this previous answer,用graph-uri替換file_contents。此外,您將「graph-uri」設置爲GET和POST參數,這些參數可能會發生衝突,並且graph-uri GET參數不是URL編碼,在shell和PHP中可能會有不同的表現。因此,您可以嘗試以下操作:

http://127.0.0.1/ws?graph-uri=http%3A%2F%2Flocalhost%2Fdataset%2Fimport%2F