1
这是我必须复制:转换卷曲 - 从CLI到PHP
curl --basic
--user testuser:testuser
--form [email protected]
--form [email protected]
http://localhost:9263/repository/document
这是我到目前为止有:
$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);
贴现的事实API没有返回一个错误,对API的调用似乎没有做任何事情,我的CURL翻译是否好?我只是试图从等式中删除一些东西。
编辑#1:虽然我消毒后(和删除调试输出),我已经删除了$缓冲= curl.exec($ curl_handle)行...
编辑#2:每FANIS'的建议,我更换了文件调用
$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);
你错过了'curl_exec()'来实际执行调用。除此之外,curl中的“@”运算符不能像PHP的curl函数afaik那样工作,您需要将文件内容作为字符串获取到变量中。 – Fanis
@Fanis在消毒过程中,我已经删除了执行电话。我把它放回到我的例子中。 – TekiusFanatikus
@Fanis发布您的建议(张贴字符串而不是文件),我会接受它。我遇到了使用CLI的相同错误。因此,可以肯定地说,它现在按预期工作。谢谢! – TekiusFanatikus