以下是我用於連接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' 。 –