簡體   English   中英

如何在php soap請求信封上發送Null參數?

[英]How can I send the Null Parameter on php soap request envelope?

我已經嘗試了幾天,但沒有成功

這是我的代碼:

<?$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中看不到任何錯誤。 任何幫助將不勝感激; 提前致謝!

如我所見,您只是復制並粘貼了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請求。 它是一個免費程序,可以下載並且易於管理。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM