2014-03-18 176 views
0

我想用cURL(PHP)將XML RPC api(http://www.zoho.com/creator/help/api/xml-rpc-api/xml-rpc-api-add-records.html)添加到zoho creator中。 我正在使用的代碼是:cURL(PHP)無法正常工作的XML RPC post請求

<?php 
if(isset($_POST['Submit'])) { 
    // if data is posted 
    $urltopost = "https://creator.zoho.com/api/xml/write"; 
    $xml = '<ZohoCreator> 
    <applicationlist> 
     <application name=\'myapp\'> 
      <formlist> 
       <form name=\'my form\'> 
        <add> 
         <field name=\'fieldName\'> 
          <value>value</value> 
         </field> 
        </add> 
       </form> 
      </formlist> 
     </application> 
    </applicationlist> 
</ZohoCreator>'; 

$datatopost = array (
'authtoken' => '*******', //my authtoken 
'scope' => 'creatorapi', 
'XMLString' => $xml , 
'zc_ownername' => '*****'//the owner name 
); 
// post via curl 
$ch = curl_init ($urltopost); 
curl_setopt ($ch, CURLOPT_POST, true); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); 
$returndata = curl_exec ($ch); 
?> 

但是,這是行不通的。有沒有人有辦法解決嗎?謝謝。

回答

0

使用http_build_query()$datatopost,否則其張貼multipart/form-data

curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($datatopost)); 
+0

謝謝您的回答,我沒有你所說的話,但沒有解決問題。我做了:回聲「返回的數據

{$ returndata}」;但它只顯示返回的數據!似乎並沒有發送請求。 – zakariag