How do i set this header in php using Curl? (CustomInfo element is array (nested key value pairs) and AuthenticationInfo element is array(nested key value pair))
<xml bla bla...>
<Header>
<CustomInfo>
<IsTestMessage>true</IsTestMessage>
<IsContentCompressed>false</IsContentCompressed>
</CustomInfo>
<AuthenticationInfo>
<ApplicationId>SomeId</ApplicationId>
<VersionId>0.9</VersionId>
<RelationId></RelationId>
<UserId>SomeUserId</UserId>
<Password>SomePassword</Password>
</AuthenticationInfo>
</Header>
<Body>
<!--etc...(actual xml)-->
</Body>
</xml bla bla...>
Normally i would do:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.example.com/process.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$vars); //Body
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers[] = 'key: value';
$headers[] = 'key2: value2';//and so on...
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec ($ch);
curl_close ($ch);
print $server_output ;
But how is this done when the header contains nested key value pairs?
Edit 1:
Done this way but doesnt work (real newby so i must be doing it wrong):
$headers = array();
$headers[] = array('CustomInfo' => array(
'IsTestMessage' => "true",
'IsContentCompressed' => "false")
);
$headers[] = array('AuthenticationInfo' => array(
'ApplicationId' => "SomeId",
'VersionId' => "0.9",
'RelationId' => "",
'UserId' => "SomeUserId",
'Password' => "SomePassword"
)
);
$headers = serialize($headers);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
var_dump(curl_getinfo($ch,CURLINFO_HEADER_OUT));
Warning: curl_setopt(): You must pass either an object or an array with the CURLOPT_HTTPHEADER argument
Edit 2:
When i dont serialize $headers i get:
Notice: Array to string conversion