我正在尝试连接到 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 ---"