php curl http 405错误心灵身体在线api

时间:2012-06-30 15:11:07

标签: php http soap curl server-error

我正在尝试连接Mind Body Online API(他们的论坛目前已关闭,所以我来到这里)。以下是我正在使用的代码。我收到了这个:

SERVER ERROR 405 - 不允许使用用于访问此页面的HTTP动词。无法显示您要查找的页面,因为使用了无效的方法(HTTP动词)来尝试访问。

代码:

//Data, connection, auth
    $soapUrl = "http://clients.mindbodyonline.com/api/0_5/ClassService.asmx?WSDL";
    // xml post structure

    $xml_post_string = '<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://clients.mindbodyonline.com/api/0_5/GetClasses">
            <soapenv:Header/>
            <soapenv:Body>
               <GetClasses>
                  <Request>
                     <SourceCredentials>
                        <SourceName>{username}</SourceName>
                        <Password>{password}</Password>
                        <SiteIDs>
                           <int>{siteid}</int>
                        </SiteIDs>
                     </SourceCredentials>
                     <XMLDetail>Basic</XMLDetail>
                     <PageSize>10</PageSize>
                     <CurrentPageIndex>0</CurrentPageIndex>
                     <SchedulingWindow>true</SchedulingWindow>
                  </Request>
               </GetClasses>
            </soapenv:Body>
         </soapenv:Envelope>';

       $headers = array(
                    "Content-type: text/xml;charset=\"utf-8\"",
                    "Accept: text/xml",
                    "Cache-Control: no-cache",
                    "Pragma: no-cache",
                    "SOAPAction: http://clients.mindbodyonline.com/api/0_5/GetClasses", 
                    "Content-length: ".strlen($xml_post_string),
                ); //SOAPAction: your op URL

        $url = $soapUrl;

        // PHP cURL  for https connection with auth
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        // converting
        $response = curl_exec($ch); 
        curl_close($ch);

        var_dump($response);

        // converting
        //$response1 = str_replace("<soap:Body>","",$response);
        //$response2 = str_replace("</soap:Body>","",$response1);

        // convertingc to XML
        //$parser = simplexml_load_string($response2);
        // user $parser to get your data out of XML response and to display it. 

任何帮助都会很棒,如果有人有任何使用API​​的经验,我的第一次;)

这是我要离开的堆栈上的帖子: SOAP request in PHP

编辑:

响应转储:

string(733) "soap:ServerSystem.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object. at mb.API._0_5.ClassService.GetClasses(GetClassesRequest Request) in e:\Builds\1\mb\mb-clients_stageclients\Sources\mb-clients\API\0_5\ClassService.asmx.cs:line 226 --- End of inner exception stack trace ---"

1 个答案:

答案 0 :(得分:0)

这对我有用

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.mindbodyonline.com/0_5/ClientService.asmx",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n  <soap:Body>\r\n    <GetClients xmlns=\"http://clients.mindbodyonline.com/api/0_5\">\r\n      <Request>\r\n        <SourceCredentials>\r\n                        <SourceName>xxxxxx</SourceName>\r\n                        <Password>xxxxx=</Password>\r\n                        <SiteIDs>\r\n                           <int>-99</int>\r\n                        </SiteIDs>\r\n                     </SourceCredentials>\r\n                     <ClientIDs>\r\n          <string></string>\r\n        </ClientIDs>\r\n                             <XMLDetail>Full</XMLDetail>\r\n\r\n        <SearchText>ccc@ccc.com</SearchText>\r\n      </Request>\r\n    </GetClients>\r\n  </soap:Body>\r\n</soap:Envelope>",
  CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache",
    "content-type: text/xml",
    "soapaction: http://clients.mindbodyonline.com/api/0_5/GetClients"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}