2

我已经尝试了几天了,但没有任何成功

这是我的代码:

<?$requestPesquisaTarifas = '<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Body>
<PesquisaTarifas xmlns="http://volator.com.br">
  <parTarifaHeader>
    <Sessao>
      <SiglaCiaAerea>string</SiglaCiaAerea>
      <IDSessao>long</IDSessao>
      <Verificador>string</Verificador>
      <MsgRetorno>string</MsgRetorno>
    </Sessao>
    <SegmentoIda>
      <Etapa>
        <Etapa xsi:nil="true" />
        <Etapa xsi:nil="true" />
      </Etapa>
      <IdFretamentoRotaTrechosVenda>int</IdFretamentoRotaTrechosVenda>
      <NroVoo>string</NroVoo>
      <SiglaOrigem>string</SiglaOrigem>
      <SiglaDestino>string</SiglaDestino>
      <TotalPaxADT>int</TotalPaxADT>
      <TotalPaxCHD>int</TotalPaxCHD>
      <TotalPaxINF>int</TotalPaxINF>
      <NroLugaresLivres>int</NroLugaresLivres>
      <Classe>Economica or Executiva or PrimeiraClasse</Classe>
      <IdaVolta>boolean</IdaVolta>
      <SiglaTarifaria>string</SiglaTarifaria>
    </SegmentoIda>
    <SegmentoVolta>
      <Etapa>
        <Etapa xsi:nil="true" />
        <Etapa xsi:nil="true" />
      </Etapa>
      <IdFretamentoRotaTrechosVenda>int</IdFretamentoRotaTrechosVenda>
      <NroVoo>string</NroVoo>
      <SiglaOrigem>string</SiglaOrigem>
      <SiglaDestino>string</SiglaDestino>
      <TotalPaxADT>int</TotalPaxADT>
      <TotalPaxCHD>int</TotalPaxCHD>
      <TotalPaxINF>int</TotalPaxINF>
      <NroLugaresLivres>int</NroLugaresLivres>
      <Classe>Economica or Executiva or PrimeiraClasse</Classe>
      <IdaVolta>boolean</IdaVolta>
      <SiglaTarifaria>string</SiglaTarifaria>
    </SegmentoVolta>
    <QtdPassageirosADT>int</QtdPassageirosADT>
    <QtdPassageirosCHD>int</QtdPassageirosCHD>
    <QtdPassageirosINF>int</QtdPassageirosINF>
    <SiglaClasseTarifariaIda>string</SiglaClasseTarifariaIda>
  </parTarifaHeader>
</PesquisaTarifas>
</soap:Body>
</soap:Envelope>';

$cabecalhoPesquisaTarifas = array(
'POST /WSReservaweb.asmx HTTP/1.1',
'Host: webservice.oceanair.com.br',
'Content-Type: text/xml; charset=utf-8',
'Content-Length: '. strlen( $requestPesquisaTarifas ),
'SOAPAction: "http://volator.com.br/PesquisaTarifas"');

$curlPesquisaTarifas = curl_init(); // Iniciar o Curl

curl_setopt($curlPesquisaTarifas, CURLOPT_URL, $enderecoWsdlAvianca); // O Endereço que irá acessar 
curl_setopt($curlPesquisaTarifas, CURLOPT_RETURNTRANSFER, true); // Para Retornar o resultado
curl_setopt($curlPesquisaTarifas, CURLOPT_VERBOSE , false); // Modo Verbose, para exibir o processo na tela
curl_setopt($curlPesquisaTarifas, CURLOPT_HEADER , false ); // Se precisar de retorno dos cabeçalhos
curl_setopt($curlPesquisaTarifas, CURLOPT_TIMEOUT, 30); // Tempo máximo em segundos que deve esperar responder
curl_setopt($curlPesquisaTarifas, CURLOPT_HTTPHEADER, $cabecalhoPesquisaTarifas); // Cabecalho para ser enviado 
curl_setopt($curlPesquisaTarifas, CURLOPT_FOLLOWLOCATION, true); // Seguir redirecionamentos
curl_setopt($curlPesquisaTarifas, CURLOPT_POST, true); // Usar metodo post
curl_setopt($curlPesquisaTarifas, CURLOPT_POSTFIELDS, $requestPesquisaTarifas); // Dados para serem processados
curl_setopt($curlPesquisaTarifas, CURLOPT_SSL_VERIFYPEER, false); // Caso precise verificar certificado

$resultadoPesquisaTarifa = curl_exec($curlPesquisaTarifas);

include ("arrayPesquisaTarifas.php");

include ("insertPesquisaTarifas.php");


?>

我错过了什么?每次执行代码时,我都会收到此错误:

soap:ClientServer was unable to read request. ---> There is an error in XML document (8, 36). ---> Input string was not in a correct format.

我检查并重新检查了指定的行和列,在 xml 中看不到任何错误。任何帮助将不胜感激;提前致谢!

4

1 回答 1

1

如我所见,您只是复制并粘贴了 SOAP 标头的定义,而没有输入正确的值。这样,将解释这些字段的 WebServer 无法理解您要获取的内容。您必须准确验证服务提供者如何解释数据。例如,在:

<Classe>Economica or Executiva or PrimeiraClasse</Classe>

正确的输入是:

<Classe>Economica</Classe>

如果您在使用 Web 服务时遇到困难,请尝试以下操作:

首先,您必须了解更多关于 WebServices、SOAP 和 REST 请求、WSDL 和 XML 的知识,快速浏览 www.w3schools.com 是一个好的开始。

然后,您需要向 Web 服务的提供者查询有关每个字段的含义以及字段值应如何传递的更多信息。

我还推荐 SoapUI 在开发这样的代码时测试您的 SOAP/REST 请求。这是一个免费程序,您可以下载并且易于管理。

于 2015-11-05T19:19:24.347 回答