我從一些日子面臨這個問題,但仍然無法找到任何答案或解決方案,無論是在網上或我以前的問題(其實有一些錯誤)。向ASP.NET服務器php curl嵌套數組發送肥皂帖請求
就是這種情況。我必須使用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_lenght,$ 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
列表SPED
正如你可以看到輸入格式不同的是,這裏是AddParcel「串」
它繼續與其他領域的模式,並密切與
</Parcel>
</Info>
ListSped通話完美的作品,而AddParcel不會,它總是返回一個400錯誤的請求標題。 我認爲xml是正確的,因爲我將它發送給GLS IT支持,他們確認它在直接上傳時有效。不幸的是,他們不支持php。
我正在考慮導致問題的嵌套數組,但我不覺得可能,因爲如果我正確地更改xml結構webservice的答案:「xml結構是錯誤的」。
我一直在四處尋找,我發現一些其他人有同樣的問題,但沒有找到解決方案。我想使腳本在PHP中工作,而不是使用其他語言,但我並不知道任何有關的內容。
你現在有空嗎? – Seeker