I’m using cURL to make an HTTP POST request to a zimbra SOAP server and get auth token, but I’m getting the HTML page instead of the SOAP response. What I’m doing wrong?
That’s the code
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:zimbraAccount">
<soap:Header>
<context xmlns="urn:zimbra"/>
</soap:Header>
<soap:Body>
<AuthRequest xmlns="urn:zimbraAccount">
<account by="name">{$username}</account>
<password>{$password}</password>
</AuthRequest>
</soap:Body>
</soap:Envelope>
EOD;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $this->zimbraSoapUrl);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $soapXml);
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/soap+xml']);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_VERBOSE, true);
$response = curl_exec($curl);
if (curl_errno($curl)) {
$errorMessage = curl_error($curl);
curl_close($curl);
throw new Exception("Erro cURL: $errorMessage");
}
$response = curl_exec($curl);
curl_close($curl);
return $response;
New contributor
Sérgio Brito is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.