将Curl命令转换为PHP Curl代码(文件传输和自定义命令)

将Curl命令转换为PHP Curl代码(文件传输和自定义命令),php,curl,Php,Curl,我正在尝试转换以下Curl命令: 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, CURLOP

我正在尝试转换以下Curl命令:

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\u file\u create()
的用法似乎不错。

试试,用图形uri代替文件内容。另外,您将“graph uri”设置为GET和POST参数,这可能会发生冲突,并且graph uri GET param不是URL编码的,这在shell和PHP中的行为可能不同。因此,您可以尝试以下方法:

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

在添加cURLFile对象之前,$args是什么?@CharlotteDunois刚刚编辑了这个问题以使其明确。基本上是:一个空数组。我想看看处理这个请求的代码。