简体   繁体   English

如何在php soap请求信封上发送Null参数?

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

I have been trying this for some days now without any success 我已经尝试了几天,但没有成功

This is my code: 这是我的代码:

<?$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");


?>

What am I missing? 我想念什么? Every time I execute the code, I got this error: 每次执行代码时,都会出现此错误:

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

I checked and rechecked the row and columns specified, and can't see anything wrong in the xml. 我检查并重新检查了指定的行和列,在xml中看不到任何错误。 Any help would be highly appreciated; 任何帮助将不胜感激; thanks in advance! 提前致谢!

As I can see, you just copied and pasted the definition for the SOAP header, without putting correct values. 如我所见,您只是复制并粘贴了SOAP标头的定义,而没有放置正确的值。 That way, the WebServer who is going to interpret those fields cannot understand what you are trying to get. 这样,将要解释这些字段的WebServer无法理解您想要获得的内容。 You must verify exactly how the provider of the service interprets the data. 您必须确切验证服务提供者如何解释数据。 For example, in: 例如,在:

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

A correct input would be: 正确的输入为:

<Classe>Economica</Classe>

If you are struggling with web services try the following: 如果您在使用Web服务时遇到问题,请尝试以下操作:

First, you must understand more about WebServices, SOAP and REST requests, WSDL and XML, a quick tour in www.w3schools.com is a good start. 首先,您必须了解有关WebServices,SOAP和REST请求,WSDL和XML的更多信息,快速浏览www.w3schools.com是一个好的开始。

Then, you need to check more information with the provider of the webservice about the meaning of each field and how the field values should be passed. 然后,您需要向Web服务的提供者检查有关每个字段的含义以及应如何传递字段值的更多信息。

I also recommend SoapUI to test your SOAPs/REST requests when developing codes like that. 开发此类代码时,我还建议SoapUI测试您的SOAP / REST请求。 It is a free program that you can download and is easy to manage. 它是一个免费程序,可以下载并且易于管理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM