1

Here is what I have to replicate:

curl --basic
     --user testuser:testuser
     --form [email protected]
     --form [email protected]
     http://localhost:9263/repository/document

Here is what I have so far:

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_USERPWD, "user:pass");
curl_setopt($curl_handle,CURLOPT_URL, "http://localhost:9263/repository/document");
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl_handle,CURLOPT_POST, 1);
$post = array("xml"=>"@e:/path_to_file/old.xml","data1"=>"@e:/path_to_file/new.xml");
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $post);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);

Discounting the fact that the API isn't returning an error, that the call to the API doesn't seem to be doing anything, is my CURL translation good? I'm just trying to remove things from the equation.

Edit #1: While sanitizing my post (and removing debug output), I had removed the $buffer = curl.exec($curl_handle) line...

Edit #2: Per Fanis' suggestion, I replaced the file calls

$old_xml_string = daisy_exec_query("http://localhost:9263/repository/document/8-Multimedia?branch=1&language=2");
//omited dom operations
$new_xml_string = $dom->saveXML();  
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_USERPWD, "user:pass");
curl_setopt($curl_handle,CURLOPT_URL, "http://localhost:9263/repository/document");
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl_handle,CURLOPT_POST, 1);
$post = array("xml"=>$old_xml_string,"data1"=>$new_xml_string);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $post);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
5
  • 1
    You're missing curl_exec() to actually perform the call. Other than that, the "@" operator from curl will not work like that in PHP's curl functions afaik, you'll need to get the file's contents into the variable as a string. Commented Oct 19, 2011 at 17:37
  • @Fanis during sanitizing, I had removed the exec call. I put it back into my example. Commented Oct 19, 2011 at 17:41
  • @Fanis post your suggestion (posting a string instead of a file) and I will accept it. I'm getting the same error I was getting using the CLI. Thus, it would be safe to say that it's now working as intended. Thanks! Commented Oct 19, 2011 at 18:11
  • Cheers! Glad I could help. The funny thing is that such a "bug" wouldn't even appear in any error logs, as there's no error. You'd only spot the missing HTTP call in your endpoint's access logs. Commented Oct 20, 2011 at 9:57
  • @Fanis that's what I meant, the API end of things wasn't showing any errors in it's log (but now does thanks to your fix). Commented Oct 20, 2011 at 11:25

1 Answer 1

1

(Posting comment as answer as per TekiusFanatikus' suggestion)

The "@" operator from curl will not work like that in PHP's curl functions to include a file's contents. You'll need to get the file's contents into a variable as a string and pass that into CURLOPT_POSTFIELDS.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.