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).
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:
/*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->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;
}
Variables $glsCall, $requestBody, $gls_lenght, $soap_action come from the script itself:
$soap_action = "SOAPAction: \"http://weblabeling.gls-italy.com/AddParcel\"";
$gls_lenght = strlen($xml);
and the request is sent by the line:
/*AddParcel*/
$glsResponse = $gls->sendRequest('AddParcel', $xml, $gls_lenght, $soap_action);
/*ListSped*/
$glsResponse = $gls->sendRequest('ListSped', $xml, $gls_lenght, $soap_action);
Now both calls are constructed in the same way, but one of them is nested:
$Label = array(
'XMLInfoParcel' => array(
'Info' => array(
'SedeGls' => $SedeGls,
'CodiceClienteGls' => $CodiceClienteGls,
'PasswordClienteGls' => $PasswordClienteGls,
'Parcel' => array(
'CodiceContrattoGls' => $cod_cont,
'RagioneSociale' => $rag_soc,
'Indirizzo' => $delivery_indirizzo,
'Localita' => $delivery_city,
'Zipcode' => $data['delivery_postcode'],
'Provincia' => $data['zone_code'],
'Bda' => '',
'DataDocumentoTrasporto' => '',
'Colli' => '1',
'Incoterm' => '',
'PesoReale' => '1,00',
'ImportoContrassegno' => $imp_cont,
'NoteSpedizione' => $data['customers_telephone'],
'TipoPorto' => 'F',
'Assicurazione' => $ass_ins,
'PesoVolume' => '',
'TipoCollo' => $tipo_collo,
'FrancoAnticipata' => '',
'RiferimentoCliente' => '',
'NoteAggiuntive' => '',
'CodiceClienteDestinatario' => '',
'Email' => '',
'Cellulare1' => $telefono,
'Cellulare2' => '',
'ServiziAccessori' => '',
'ModalitaIncasso' => $mod_inc
),),),
);
and the other one is not:
/*Request*/
$listsp = array(
'SedeGls' => $SedeGls,
'CodiceClienteGls' => $CodiceClienteGls,
'PasswordClienteGls' => $PasswordClienteGls
);
those are requested input:
AddParcel

List Sped

As you can see the input format is different, here is the schema of AddParcel "string"

It continues with other fields and close with
</Parcel>
</Info>
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.
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".
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.