/** * Lancement d'une requête * * @param CopixHTTPClientRequest $pRequest * @return unknown */ private function _launchRequest(CopixHTTPClientRequest $pRequest) { if (CopixConfig::get('default|proxyEnabled')) { //proxy_host, proxy_port, proxy_login et proxy_password curl_setopt($this->_curl, CURLOPT_HTTPPROXYTUNNEL, true); if (CopixConfig::get('default|proxyHost') != null) { curl_setopt($this->_curl, CURLOPT_PROXY, str_replace('http://', '', CopixConfig::get('default|proxyHost'))); } if (CopixConfig::get('default|proxyPort') != null) { curl_setopt($this->_curl, CURLOPT_PROXYPORT, intval(CopixConfig::get('default|proxyPort'))); } if (CopixConfig::get('default|proxyUser') != null) { $proxyUserPass = CopixConfig::get('default|proxyUser'); if (CopixConfig::get('default|proxyPass') != null) { $proxyUserPass .= ':' . CopixConfig::get('default|proxyPass'); } curl_setopt($this->_curl, CURLOPT_PROXYUSERPWD, $proxyUserPass); } } curl_setopt($this->_curl, CURLOPT_TIMEOUT, $pRequest->getTimeout()); // Choix de l'interface à utiliser $interfaceUsed = $pRequest->getInterface(); // Si pas d'interface on récupère celle en configuration if ($interfaceUsed !== '') { $interfaceUsed = CopixConfig::get('default|webservicesInterface'); } // Mise en place de l'interface if (isset($interfaceUsed)) { curl_setopt($this->_curl, CURLOPT_INTERFACE, $interfaceUsed); } if ($pRequest->getIgnoreCertificate()) { curl_setopt($this->_curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($this->_curl, CURLOPT_SSL_VERIFYHOST, false); } curl_setopt($this->_curl, CURLOPT_URL, $pRequest->getUrl()); curl_setopt($this->_curl, CURLOPT_VERBOSE, 1); if ($pRequest->getHeader()) { curl_setopt($this->_curl, CURLOPT_HTTPHEADER, $pRequest->getHeader()); } if ($pRequest->getCookie()) { curl_setopt($this->_curl, CURLOPT_COOKIE, $pRequest->getCookie()); } if (count($pRequest->getPost())) { if ($pRequest->getFile()) { $boundary = uniqid('------------------'); $MPboundary = '--' . $boundary; $endMPboundary = $MPboundary . '--'; $postBody = 'Content-type: multipart/form-data, boundary=' . $boundary . "\r\n\r\n"; foreach ($pRequest->getPost() as $name => $content) { $postBody .= $MPboundary . "\r\n"; $postBody .= 'content-disposition: form-data; name="' . $name . '"' . "\r\n\r\n"; $postBody .= $content . "\r\n"; } $file = $pRequest->getFile(); $fileContent = file_get_contents($file); $postBody .= $MPboundary . "\r\n"; $postBody .= 'Content-Disposition: form-data; name="file"; filename="' . basename($file) . '"' . "\r\n"; $postBody .= 'Content-Type: ' . CopixMIMETypes::getFromFileName($file) . "\r\n"; $postBody .= 'Content-Transfer-Encoding: binary' . "\r\n\r\n"; $postBody .= $fileContent; $postBody .= "\r\n" . $endMPboundary; curl_setopt($this->_curl, CURLOPT_POST, true); curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $postBody); curl_setopt($this->_curl, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data; boundary={$boundary}")); curl_setopt($this->_curl, CURLOPT_RETURNTRANSFER, true); } else { curl_setopt($this->_curl, CURLOPT_POST, true); curl_setopt($this->_curl, CURLOPT_POSTFIELDS, CopixUrl::valueToUrl(null, $pRequest->getPost())); } } if ($pRequest->getFollowRedirect()) { curl_setopt($this->_curl, CURLOPT_FOLLOWLOCATION, 1); } else { curl_setopt($this->_curl, CURLOPT_FOLLOWLOCATION, 0); } return new CopixHTTPRequestResult($pRequest, $this->_curl); }
public function testValueToUrl() { $this->assertEquals(CopixUrl::valueToUrl('test', array(1, 2, 3, 4)), 'test[0]=1&test[1]=2&test[2]=3&test[3]=4'); $this->assertEquals(CopixUrl::valueToUrl(null, array('test' => array(1, 2, 3, 4))), 'test[0]=1&test[1]=2&test[2]=3&test[3]=4'); $this->assertEquals(CopixUrl::valueToUrl('test', array(1, 2, 3, 4), true), '&test[0]=1&test[1]=2&test[2]=3&test[3]=4'); $this->assertEquals(CopixUrl::valueToUrl(null, array('test' => array(1, 2, 3, 4)), true), '&test[0]=1&test[1]=2&test[2]=3&test[3]=4'); $this->assertEquals(CopixUrl::valueToUrl('test', array(1, 2, 3, 4), true, true), '&test[0]=1&test[1]=2&test[2]=3&test[3]=4'); $this->assertEquals(CopixUrl::valueToUrl(null, array('test' => array(1, 2, 3, 4)), true, true), '&test[0]=1&test[1]=2&test[2]=3&test[3]=4'); }