Im trying to do a post call with soap in laravel 8, to get some data, but if i put headers on call, his return error 500, i show the code below, also if no headers is defined, is geting empty response
try {
$data = $this->generateXml($get_last_day);
$client = new Client(['verify' => false ]);
$headers = [
'SOAPAction' => "https://api.xyz.com/DataService/PostData",
'Content-Type' => "text/xml"
];
$get_invoices_only_paid = $client->request('POST', config('constants.service.URL'), [
'headers' => $headers,
'body' => $data
]);
Log::debug(json_encode($get_invoices_only_paid->getStatusCode()));
dd($get_invoices_only_paid->getStatusCode());
} catch (Exception $e) {
dd($e->getCode(), $e->getMessage());
}
xml soap i passed:
public function generateXml($date)
{
// $xml = new SimpleXMLElement('<inf:getInvoicingTransactions xmlns:inf="http://infoservice.webservice.as24.com/"><date>'.$date->format("Y-m-d").'</date></inf:getData>');
$xml = new SimpleXMLElement('<inf:getInvoicingTransactions xmlns:inf="http://infoservice.webservice.as24.com/"><date>2024-04-15</date></inf:getData>');
$customXML = new SimpleXMLElement($xml->asXML());
$dom = dom_import_simplexml($customXML);
$cleanXml = $dom->ownerDocument->saveXML($dom->ownerDocument->documentElement);
$soapHeader = '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><wsse:UsernameToken wsu:Id="UsernameToken-16" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsse:Username>username</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password></wsse:UsernameToken></wsse:Security></SOAP-ENV:Header><soap:Body>';
$soapFooter = '</soap:Body></soap:Envelope>';
$xmlRequest = $soapHeader . $cleanXml . $soapFooter;
return $xmlRequest;
}
and the error after call:
500
"""
Server error: `POST https://services.as24.com:8445/infoservice/services/infoservice` resulted in a `500 500` response:n
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Server</fau (truncated...)n
"""
the same request in postman works perfectly with the same headers and body data
1