title: Soap post request to ASP.NET server php curl nested array
body: <p>I'm facing this problem from some days but still i can't find any answer or solution either on the net or to my previous question (wich actually had some errors).</p>
  
  <p>That's the scenario. I have to consume gls webservice to add parcel or list inserted parcel.
  I'm using curl to construct client and make the call, here is the code from the class:</p>
  
  <pre><code>/*Headers*/
  public function buildGlsHeaders($glsCall,$gls_lenght,$soap_action)
  {       
      //header soap 1.1
      $headers = array(
          "Content-Type: text/xml; charset=utf-8",
          "Content-Length: " . $gls_lenght,
          $soap_action,
          );
  
      return $headers;
  }
  
  /*Request*/
  public function sendRequest($glsCall, $requestBody, $gls_lenght, $soap_action)
  {
      $cookiePath = tempnam('/tmp', 'cookie');
  
      //build gls headers using variables passed via constructor as well as the gls call to use
      $headers = $this-&gt;buildGlsHeaders($glsCall, $gls_lenght, $soap_action);
  
      //initialise a CURL session
      $connection = curl_init();
  
      //set the server we are using 
      curl_setopt($connection, CURLOPT_URL, 'http://weblabeling.gls-italy.com/IlsWebService.asmx');
  
      //Time out
      curl_setopt($connection, CURLOPT_CONNECTTIMEOUT, 10);
      curl_setopt($connection, CURLOPT_TIMEOUT, 10);
  
      //set it to return the transfer as a string from curl_exec
      curl_setopt($connection, CURLOPT_RETURNTRANSFER, true);
  
      //stop CURL from verifying the peer's certificate
      curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, false);
  
      //set method as POST
      curl_setopt($connection, CURLOPT_POST, true);
  
      //set the XML body of the request
      curl_setopt($connection, CURLOPT_POSTFIELDS, $requestBody);
  
      //set the headers using the array of headers
      curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);
  
      //Header
      curl_setopt($connection, CURLINFO_HEADER_OUT, true);
      curl_setopt($connection, CURLOPT_HEADER, true);
  
      curl_setopt($connection, CURLOPT_COOKIEJAR, $cookiePath);
  
      //Send the Request
      $response = curl_exec($connection);
  
      print_r(curl_getinfo($connection));
  
      echo "\n" . 'Header Code: ' . curl_getinfo($connection, CURLINFO_HTTP_CODE) . "\n\n";
  
      //close the connection
      curl_close($connection); 
  
      //return the response
      return $response;
  }
  </code></pre>
  
  <p>Variables $glsCall, $requestBody, $gls_lenght, $soap_action come from the script itself:</p>
  
  <pre><code>$soap_action = "SOAPAction: \"http://weblabeling.gls-italy.com/AddParcel\"";
  
  $gls_lenght = strlen($xml); 
  </code></pre>
  
  <p>and the request is sent by the line:</p>
  
  <pre><code>/*AddParcel*/
  $glsResponse = $gls-&gt;sendRequest('AddParcel', $xml, $gls_lenght, $soap_action);
  
  /*ListSped*/
  $glsResponse = $gls-&gt;sendRequest('ListSped', $xml, $gls_lenght, $soap_action);
  </code></pre>
  
  <p>Now both calls are constructed in the same way, but one of them is nested:</p>
  
  <pre><code>$Label = array(
                  'XMLInfoParcel' =&gt; array(
                  'Info' =&gt; array(
                      'SedeGls' =&gt; $SedeGls,
                      'CodiceClienteGls' =&gt; $CodiceClienteGls,
                      'PasswordClienteGls' =&gt; $PasswordClienteGls,                
                      'Parcel' =&gt; array(
                                         'CodiceContrattoGls' =&gt; $cod_cont,
                                         'RagioneSociale' =&gt; $rag_soc,
                                         'Indirizzo' =&gt; $delivery_indirizzo,
                                         'Localita' =&gt; $delivery_city,
                                         'Zipcode' =&gt; $data['delivery_postcode'],
                                         'Provincia' =&gt; $data['zone_code'],
                                         'Bda' =&gt; '',
                                         'DataDocumentoTrasporto' =&gt; '',
                                         'Colli' =&gt; '1',
                                         'Incoterm' =&gt; '',
                                         'PesoReale' =&gt; '1,00',
                                         'ImportoContrassegno' =&gt; $imp_cont,
                                         'NoteSpedizione' =&gt; $data['customers_telephone'],
                                         'TipoPorto' =&gt; 'F',
                                         'Assicurazione' =&gt; $ass_ins,
                                         'PesoVolume' =&gt; '',
                                         'TipoCollo' =&gt; $tipo_collo,
                                         'FrancoAnticipata' =&gt; '',
                                         'RiferimentoCliente' =&gt; '',
                                         'NoteAggiuntive' =&gt; '',
                                         'CodiceClienteDestinatario' =&gt; '',
                                         'Email' =&gt; '',
                                         'Cellulare1' =&gt; $telefono,
                                         'Cellulare2' =&gt; '',
                                         'ServiziAccessori' =&gt; '',
                                         'ModalitaIncasso' =&gt; $mod_inc    
                                    ),),),                                
                  );
  </code></pre>
  
  <p>and the other one is not:</p>
  
  <pre><code>/*Request*/
      $listsp = array(
                      'SedeGls' =&gt; $SedeGls,
                      'CodiceClienteGls' =&gt; $CodiceClienteGls,
                      'PasswordClienteGls' =&gt; $PasswordClienteGls 
                      );
  </code></pre>
  
  <p>those are requested input:</p>
  
  <p>AddParcel</p>
  
  <p><img src="https://i.stack.imgur.com/18t1B.jpg" alt="enter image description here"></p>
  
  <p>List Sped</p>
  
  <p><img src="https://i.stack.imgur.com/kqv6F.jpg" alt="enter image description here"></p>
  
  <p>As you can see the input format is different, here is the schema of AddParcel "string"</p>
  
  <p><img src="https://i.stack.imgur.com/aIxmP.png" alt="enter image description here"></p>
  
  <p>It continues with other fields and close with </p>
  
  <pre><code>       &lt;/Parcel&gt;
    &lt;/Info&gt;
  </code></pre>
  
  <p>ListSped call works perfectly while AddParcel doesn't, it always return a 400 Bad request header.
  I assume xml is correct since i sent it to GLS IT support and they confirm me it works when uploaded directly. Unfortunatly they don't give support for php.</p>
  
  <p>I was thinking about the nested array causing the problem but i don't feel like possible since if i change xml structure webservice answers correctly: "xml structure is wrong".</p>
  
  <p>I've been looking around and i found some other people with the same problems but no solutions is found. I would like to make the script works in php instead of using other languages wich i don't really know anything about.</p>