PHP curl Soap请求返回404

时间:2014-08-26 08:19:07

标签: php curl soap

我尝试使用PHP cURL和SOAP来向公共服务器执行请求,然后公用服务器应该响应一些图像网址。

我设法把它全部设置好了,问题是,我得到的回应是404 - 找不到文件或目录。据我所知,我遵循了服务提供商使用SOAP的方法。我正在提供一个" nobbnr"这是一个产品标识符,然后应该用于返回产品图像。我错过了什么吗?网址看起来是否正确?

他们的"食谱"如下: http://produktinfo.byggtjeneste.no/ProduktInfo.asmx?op=HentMedierForNobbNo (看看肥皂1.1)

我的完整PHP代码如下:

 <?php
  $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 .= "    <HentMedierForNobbNo xmlns=\"http://produktinfo.byggtjeneste.no/\">\n";
  $soap_request .= "      <nobbnr>10871051</nobbnr>\n";
  $soap_request .= "    </HentMedierForNobbNo>\n";
  $soap_request .= "  </soap:Body>\n";
  $soap_request .= "</soap:Envelope>";

  $header = array(
    "POST /ProduktInfo.asmx HTTP/1.1",
    "Host: produktinfo.byggtjeneste.no",
    "Content-type: text/xml; charset=utf-8",
    "Content-length: ".strlen($soap_request),
    "SOAPAction: \"http://produktinfo.byggtjeneste.no/HentMedierForNobbNo\""
  );

  $soap_do = curl_init();
  curl_setopt($soap_do, CURLOPT_URL, "http://produktinfo.byggtjeneste.no/HentMedierForNobbNo" );
  curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
  curl_setopt($soap_do, CURLOPT_TIMEOUT,        10);
  curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
  curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($soap_do, CURLOPT_POST,           true );
  curl_setopt($soap_do, CURLOPT_POSTFIELDS,     $soap_request);
  curl_setopt($soap_do, CURLOPT_HTTPHEADER,     $header);

  $xml_result = curl_exec($soap_do);
  // check for errors
  if ($xml_result === false) {
  $error_occurred = true;
  }
  else {

      $xml = new SimpleXMLElement($xml_result);

      print_r($xml);
  }
?>

1 个答案:

答案 0 :(得分:0)

更正您要尝试访问的服务的网址是http://produktinfo.byggtjeneste.no/ProduktInfo.asmx/HentMedierForNobbNo

BTW:看一下http://php.net//manual/pl/class.soapclient.php(或任何其他像nuSoap这样的肥皂客户端)。您不必手动创建请求XML。你也可以在调用方法时得到响应对象。

编辑:

正如我上面提到的 - 尝试使用SoapClient:

$client = new SoapClient('http://produktinfo.byggtjeneste.no/ProduktInfo.asmx?WSDL',
                array(
                    'cache_wsdl' => WSDL_CACHE_NONE,
                    'encoding' => 'utf-8',
                    'soap_version' => SOAP_1_1,
                    'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
                    'trace' => 1
                )
);

之后你需要做的就是调用正确的方法:

$params = new StdClass();
$params->nobbnr = 10871051;
var_dump($client->HentMedierForNobbNo($params));