我想使用带有cURL(PHP)的XML RPC api(http://www.zoho.com/creator/help/api/xml-rpc-api/xml-rpc-api-add-records.html)向zoho创建者添加记录。 我正在使用的代码是:
<?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 :(得分:0)
在http_build_query()
上使用$datatopost
,否则将其发布为multipart/form-data
curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($datatopost));