PHP&;XML-如何生成soap请求错误415


PHP & XML - How to generate a soap request error 415

如果有人能帮我的话,为什么我会得到错误415我不明白为什么会出现错误链接到错误http://agency.lastminute-hr.com/stranice/upisi_destinacije_unico.php

这就是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是从用curl触发的HTTP请求的响应中获得的HTTP状态代码

这些代码是标准化的并有文档记录的,在您的415:中

415不支持的媒体类型

服务器拒绝为请求提供服务,因为请求的实体的格式不受请求方法的请求资源支持。

请求的实体表示请求主体,即POST方法的请求主体。简而言之,这意味着您发送到服务器的数据不符合它的需要。

您必须首先修复发送到服务器的数据,否则所有后续操作(如将响应字符串加载到simplexml中)也将失败。

或者,如果你确信你正确地遵循了Web服务的规范,你唯一能做的就是正确的错误处理,也就是说,如果服务器为你的请求返回了一个错误(代码400到499),不进一步处理返回值,而只是发信号通知错误条件。

此XML对您使用的Web服务无效。

粘贴到此处:http://wl.filos.com.gr/services/WebService.asmx?op=PlaceSearch并检查错误的