PHP与XML - 如何生成一个SOAP请求错误415
问题描述:
为什么我收到错误415,如果有人能帮助我 我不明白为何出现错误 链接错误 http://agency.lastminute-hr.com/stranice/upisi_destinacije_unico.phpPHP与XML - 如何生成一个SOAP请求错误415
这是怎样的XML
POST /services/WebService.asmx HTTP/1.1
Host: wl.filos.com.gr
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<PlaceSearch xmlns="http://www.cyberlogic.gr/webservices/">
<xml>string</xml>
</PlaceSearch>
</soap12:Body>
</soap12:Envelope>
我的代码是:
$soapUrl = "http://wl.filos.com.gr/services/WebService.asmx?op=PlaceSearch";
$soap_request = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
$soap_request .= "<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/\">\n";
$soap_request .= " <soap:Body>\n";
$soap_request .= " <PlaceSearch xmlns=\"http://www.cyberlogic.gr/webservices/\">\n";
$soap_request .= " <xml><PlaceSearchRequest><Username>******</Username><Password>******</Password><PlaceType>Cities</PlaceType><Language>en</Language></PlaceSearchRequest></xml>\n";
$soap_request .= " </PlaceSearch>\n";
$soap_request .= " </soap:Body>\n";
$soap_request .= "</soap:Envelope>";
$xml_post_string = $soap_request;
$headers = array(
"POST /services/WebService.asmx HTTP/1.1",
"Host: wl.filos.com.gr",
"Content-Type: application/soap+xml; charset=utf-8",
"Content-Length: ".strlen($xml_post_string)
);
$url = $soapUrl;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, ($xml_post_string));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
// echo results
echo "The server responded: <br />";
echo " " . $info['http_code']. " <br />";
curl_close($ch);
$response1 = str_replace("<soap12:Body>","",$response);
$response2 = str_replace("</soap12:Body>","",$response1);
$parser = simplexml_load_string($response2);
答
415是HTTP状态代码你从火中袅袅的HTTP请求的响应获得。
这些代码是standardized and documented,在你的415案:
415不支持的媒体类型
服务器拒绝,因为请求的实体的格式不能以服务请求由请求的资源为请求的方法提供支持。
请求的实体表示请求主体,它是POST方法的请求主体。简而言之,这意味着您发送给服务器的数据不符合需求。
您必须首先修复发送给服务器的数据,否则后面的所有操作(如将响应字符串加载到simplexml中)都将失败。另外,如果你确定你正确地遵循了web服务的规范,你唯一可以做的就是正确的错误处理,也就是说,如果服务器为你的请求返回一个错误(代码400到499)不是进一步处理返回值,但只是表示错误情况。
这与您自己和已经问过的问题有什么不同? 415是不支持媒体类型的代码。您必须以Web服务端点接受的格式创建请求XML数据。你仍然不这样做。具有* XML示例的webservice *的文档位于:http://wl.filos.com.gr/services/WebService.asmx?op=PlaceSearch - 即使有一些测试工具。 – hakre 2014-11-02 12:32:46