以下是我用于连接Mind Body Online API的代码。如果任何人都有这方面的经验,请指出我的方向正确!xml php curl请求不受支持的媒体类型
我得到的错误是:服务器无法为请求提供服务,因为媒体类型不受支持。
代码:
$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:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<GetClasses xmlns="http://clients.mindbodyonline.com/api/0_5/GetClasses">
<Request>
<SourceCredentials>
<SourceName>{user}</SourceName>
<Password>{pass}</Password>
<SiteIDs>
<int>{id}</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: application/xml;charset=utf-8",
"Accept: application/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: http://clients.mindbodyonline.com/api/0_5/GetClasses",
"Content-length: ".strlen($xml_post_string),
);
$url = $soapUrl;
$cookiePath = tempnam('/tmp', 'cookie');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiePath);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// converting
$response = curl_exec($ch);
curl_close($ch);
echo $response;
这是非常棘手的,先生!请用萤火虫检查并手动尝试此过程。从普通查询记录萤火虫的成功请求/响应,然后我们可以评估您在请求中做错了什么。与真正的标题和cookie完全匹配的CURL请求不会失败,但在知道详细信息之前,我们无法诊断问题。如果不是萤火虫,至少试试命令行:“curl -I site.com/ajaxcall”并回报。说真的,我的意思是你没有冒犯,因为我问了更多含糊的问题。但是,如果您提供更好的细节,则会有人回答。 –
我刚遇到同样的错误。响应的主体是你提到的,但看看HTTP响应头提供了更多的细节,如: HTTP/1.1 415由于内容类型'application/soap + xml; charset = UTF-8; action =“,无法处理消息http://www.foo.org/bar/Operation“'不是预期的类型'text/xml;字符集= UTF-8' 。 –