对ASP.NET服务器php curl嵌套数组的Soap post请求

对ASP.NET服务器php curl嵌套数组的Soap post请求,php,soap,curl,Php,Soap,Curl,几天来我一直在面对这个问题,但我仍然无法在网上或我之前的问题上找到任何答案或解决方案(wich实际上有一些错误) 情况就是这样。我必须使用gls webservice来添加包裹或列出插入的包裹。 我使用curl构造客户机并进行调用,下面是来自该类的代码: /*Headers*/ public function buildGlsHeaders($glsCall,$gls_lenght,$soap_action) { //header soap 1.1 $headers

几天来我一直在面对这个问题,但我仍然无法在网上或我之前的问题上找到任何答案或解决方案(wich实际上有一些错误)

情况就是这样。我必须使用gls webservice来添加包裹或列出插入的包裹。 我使用curl构造客户机并进行调用,下面是来自该类的代码:

/*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;
}
变量$glsCall、$requestBody、$gls_lengh、$soap_action来自脚本本身:

$soap_action = "SOAPAction: \"http://weblabeling.gls-italy.com/AddParcel\"";

$gls_lenght = strlen($xml); 
请求通过以下线路发送:

/*AddParcel*/
$glsResponse = $gls->sendRequest('AddParcel', $xml, $gls_lenght, $soap_action);

/*ListSped*/
$glsResponse = $gls->sendRequest('ListSped', $xml, $gls_lenght, $soap_action);
现在,两个调用的构造方式相同,但其中一个是嵌套的:

$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    
                                  ),),),                                
                );
另一个不是:

/*Request*/
    $listsp = array(
                    'SedeGls' => $SedeGls,
                    'CodiceClienteGls' => $CodiceClienteGls,
                    'PasswordClienteGls' => $PasswordClienteGls 
                    );
这些是请求的输入:

地址包

列表速度

正如您所看到的,输入格式不同,下面是AddParcel“string”的模式

它与其他字段一起继续,与其他字段一起结束

       </Parcel>
  </Info>

ListSped调用可以很好地工作,而AddParcel不能,它总是返回一个400错误的请求头。 我假设xml是正确的,因为我将它发送给了GLS it支持部门,他们确认我直接上传时它可以工作。不幸的是,他们不支持php

我在考虑导致问题的嵌套数组,但我觉得不可能,因为如果我更改xml结构,webservice会正确回答:“xml结构错误”


我四处寻找,发现其他人也有同样的问题,但没有找到解决办法。我想让脚本在php中工作,而不是使用我不太了解的其他语言。

正如我们在请求输入的图片“AddParcel”中看到的,输入本身是一个字符串

我意识到它希望将其格式化为:

    &lt;Info&gt;&lt;SedeGls&gt;XXX&lt;/SedeGls&gt;&lt;CodiceContrattoGls&gt;XXX&lt;/CodiceContrattoGls&gt; <!--and so on-->
InfoSedeGlsXXX/sedeglscodicecontractoglsxxx/codicecontractogls

正如我们在请求输入的图片“AddParcel”中看到的,输入本身是一个字符串

我意识到它希望将其格式化为:

    &lt;Info&gt;&lt;SedeGls&gt;XXX&lt;/SedeGls&gt;&lt;CodiceContrattoGls&gt;XXX&lt;/CodiceContrattoGls&gt; <!--and so on-->
InfoSedeGlsXXX/sedeglscodicecontractoglsxxx/codicecontractogls

法比奥,你现在有空吗?法比奥,你现在有空吗?