1

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

服务器错误 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 的经验,我是第一次 ;)

这是我要离开的堆栈上的帖子: PHP中的SOAP请求

编辑:

var转储响应:

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 ---"
4

1 回答 1

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;
}
于 2018-05-09T19:02:10.207 回答