protected function doRequest($methode) { /* Construct field string like ?var1=val1&var2=val2... */ $fields_string = ""; if (is_array($this->arrParams)) { $fields_string = http_build_query($this->arrParams); } $isXmlToSend = isset($this->xmlToSend) && $this->xmlToSend != "" ? true : false; /* Init curl */ if ($methode == "GET") { if ($fields_string != "") { $fields_string = "?" . $fields_string; } echo "URL request [GET] : " . $this->url . $fields_string . "<br /><br />"; $process = curl_init($this->url . $fields_string); curl_setopt($process, CURLOPT_POST, 0); } else { if ($methode == "PUT") { if ($isXmlToSend) { if ($fields_string != "") { $fields_string = "?" . $fields_string; } $process = curl_init($this->url . $fields_string); echo "URL request [PUT] : " . $this->url . $fields_string . "<br /><br />"; } else { $process = curl_init($this->url); curl_setopt($process, CURLOPT_POSTFIELDS, $fields_string); curl_setopt($process, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen($fields_string))); } curl_setopt($process, CURLOPT_CUSTOMREQUEST, 'PUT'); } else { if ($isXmlToSend) { if ($fields_string != "") { $fields_string = "?" . $fields_string; } $process = curl_init($this->url . $fields_string); echo "URL request [POST] : " . $this->url . $fields_string . "<br /><br />"; } else { $process = curl_init($this->url); curl_setopt($process, CURLOPT_POSTFIELDS, $fields_string); curl_setopt($process, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen($fields_string))); } curl_setopt($process, CURLOPT_POST, 1); } } /* Send XML into body */ if ($isXmlToSend) { curl_setopt($process, CURLOPT_HTTPHEADER, array('Content-Type: text/xml')); curl_setopt($process, CURLOPT_POSTFIELDS, $this->xmlToSend); echo "XML request : <br /><textarea rows='5' cols='100'>" . $this->xmlToSend . "</textarea><br /><br />"; } curl_setopt($process, CURLOPT_TIMEOUT, $this->timeout); curl_setopt($process, CURLOPT_CONNECTTIMEOUT, $this->timeout); curl_setopt($process, CURLOPT_RETURNTRANSFER, 1); curl_setopt($process, CURLOPT_USERPWD, $this->httpLogin . ":" . $this->httpPasswd); curl_setopt($process, CURLOPT_SSL_VERIFYPEER, false); //check certificat /* Test connection to webservices, 10x */ for ($i = 0; $i < 10; $i++) { $resultReq = curl_exec($process); if ($resultReq === FALSE) { /* Wait one second to retry the connection */ sleep(1); $resultReq = null; } else { break; } } /* If you have not been able to connect 10 times, it throws an exception and stops */ if (!isset($resultReq)) { throw new Exception("error curl request (method=" . $methode . ") : '" . curl_error($process) . "'"); } $code = curl_getinfo($process, CURLINFO_HTTP_CODE); curl_close($process); $reqAction = $this->arrParams["action"]; $responseObj = new CurlResponse($reqAction, $code, $resultReq); echo "ResponseObject : <br /><textarea rows='5' cols='100'>" . $responseObj->getResponse() . "</textarea><br />Code return " . $responseObj->getCode() . "<br /><br />"; return $responseObj; }