2

I am trying to convert the following Curl command:

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

Here is the code that appears to be ok, but that doesn't work:

$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);

It seems that the file is actually not uploaded with the PHP code, but everywhere I look the usage of curl_file_create() seems good.

Neoasimov
  • 1,111
  • 2
  • 10
  • 17

1 Answers1

0

Try this previous answer, substituting graph-uri for file_contents. Also, you are setting "graph-uri" as both GET and POST params, which could collide, and the graph-uri GET param is not URL encoded, which could behave differently in the shell vs. PHP. So you might try the following:

http://127.0.0.1/ws?graph-uri=http%3A%2F%2Flocalhost%2Fdataset%2Fimport%2F
Community
  • 1
  • 1
jaybrau
  • 403
  • 1
  • 3
  • 9