douchuang1861 2011-10-19 17:34
浏览 35
已采纳

转换cURL - 从CLI转换为PHP

Here is what I have to replicate:

curl --basic
     --user testuser:testuser
     --form xml=@newdoc.xml
     --form data1=@mynewfile.xml
     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);
  • 写回答

1条回答 默认 最新

  • dtl4521 2011-10-20 09:55
    关注

    (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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 怎样才能让鼠标沿着线条的中心线轨迹移动
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?