1

我向 SAASU 发送请求以使用 REST API 创建新联系人,但我没有得到结果。请帮我。

方法一

$web_service = 'https://secure.saasu.com/webservices/rest/r1/Tasks?wsaccesskey=XXXXXXXXXXXXXXXXX&FileUid=XXX';

$xml = '<?xml version="1.0" encoding="utf-8"?><tasks><insertContact><contact uid="0"><salutation>Mr.</salutation><familyName>Smith</familyName><givenName>John</givenName><organisationName></organisationName></contact></insertContact></tasks>';

$cmd = 'curl -X '.' "'.$xml.'" '.$web_service;

exec($cmd, $result);

print_r($result); // Getting Null

方法二

$curlData = '<?xml version="1.0" encoding="utf-8"?><tasks><insertContact><contact uid="0"><salutation>Mr.</salutation><familyName>Smith</familyName><givenName>John</givenName><organisationName></organisationName></contact></insertContact></tasks>';
$url = https://secure.saasu.com/webservices/rest/r1/Tasks?wsaccesskey=XXXXXXXXXXXXXXXXX&FileUid=XXX';
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl,CURLOPT_HTTPHEADER,array (
    'SOAPAction:""',
    'Content-Type: text/xml; charset=utf-8',
));

curl_setopt ($curl, CURLOPT_POST, 1);
curl_setopt ($curl, CURLOPT_POSTFIELDS, $curlData);

$result = curl_exec($curl);
curl_close ($curl);
print_r($result); //NULL RESULT

萨苏帮助:http ://help.saasu.com/api/

4

1 回答 1

0

终于,得到了回应。这是代码

$curlData = '<?xml version="1.0" encoding="utf-8"?><tasks><insertContact><contact uid="0"><salutation>Mr.</salutation><familyName>Smith</familyName><givenName>John</givenName><organisationName></organisationName></contact></insertContact></tasks>';
$url = https://secure.saasu.com/webservices/rest/r1/Tasks?wsaccesskey=XXXXXXXXXXXXXXXXX&FileUid=XXX';

$curl = curl_init();
    curl_setopt ($curl, CURLOPT_URL, $url);
    //curl_setopt ($curl, CURLOPT_URL, "http://www.php.net");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_VERBOSE, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);

    curl_setopt ($curl, CURLOPT_POST, 1);
    curl_setopt ($curl, CURLOPT_POSTFIELDS, $curlData);

   $curl_response = curl_exec ($curl);
    curl_close ($curl);

    $xml = new SimpleXMLElement($curl_response);
    print_r($xml);

谢谢

于 2013-07-09T11:48:34.607 回答