A
A
Alessandro29812018-08-29 09:12:05
PHP
Alessandro2981, 2018-08-29 09:12:05

How to generate a SOAP request in PHP with multiple parameters with the same name?

I need to generate a SOAP request of this kind, where the status parameter is repeated several times with different values:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    	<soapenv:Header/> 
    	<soapenv:Body> 
    		<ns1:SomeRequest enddate="01-01-2018 00:00:00" authCode="exampleexample"> 
    			<ns1:status>STATUS1</ns1:status> 
    			<ns1:status>STATUS2</ns1:status> 
    		</ns1:SomeRequest> 
    	</soapenv:Body> 
</soapenv:Envelope>

I am trying to implement it like this:
$this->client = new SoapClient($this->wsdlUrl, [
     'trace' => true,
     'exception' => true,
     'cache_wsdl' => WSDL_CACHE_NONE,
]);
    
$parameters = [
        'authCode' => 'exampleexample',
        'enddate' => '01-01-2018 00:00:00',
        'status' => ['STATUS1', 'STATUS2']
];
    
$response = $this->client->SomeSimpleMethod($parameters);

I am getting an Array to string conversion error .
If I send the status as a string, then everything works fine:
$parameters = [
        'authCode' => 'exampleexample',
        'enddate' => '01-01-2018 00:00:00',
        'status' => 'STATUS1'
];

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max Cohen, 2018-09-10
@Max_Cohen

Good afternoon,
Most likely you can send an array, but you won't be able to output it somewhere as "text". You need to convert the array to a string. You can use the native function: Or, you can't send a request with an array at all?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question