Exemple #1
0
 private function createDownloaderConfig($xmlData, $endpointUrl)
 {
     $postData = new RawPostData($xmlData);
     $config = new Config($endpointUrl);
     $config->setPostData($postData);
     $config->setConnectionTimeout(30);
     $config->setUserAgent('Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0');
     $config->setHeaders(array('Connection' => 'close', 'Accept-Encoding' => 'gzip, deflate', 'Accept-Language' => 'cs,en-us;q=0.7,en;q=0.3', 'Accept-Charset' => 'utf-8,ISO-8859-1;q=0.7,*;q=0.7', 'Content-Type' => 'text/xml'));
     return $config;
 }
Exemple #2
0
 public function downloadPage(Config $config)
 {
     $curlConnection = curl_init($config->getUrl());
     if ($config->getConnectionTimeout()) {
         curl_setopt($curlConnection, CURLOPT_CONNECTTIMEOUT, $config->getConnectionTimeout());
     }
     if ($config->getUserAgent()) {
         curl_setopt($curlConnection, CURLOPT_USERAGENT, $config->getUserAgent());
     }
     curl_setopt($curlConnection, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curlConnection, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($curlConnection, CURLOPT_FOLLOWLOCATION, true);
     curl_setopt($curlConnection, CURLOPT_VERBOSE, true);
     curl_setopt($curlConnection, CURLOPT_HEADER, true);
     curl_setopt($curlConnection, CURLOPT_VERBOSE, false);
     if ($config->getCookiesStorageFile()) {
         curl_setopt($curlConnection, CURLOPT_COOKIEJAR, $config->getCookiesStorageFile());
         curl_setopt($curlConnection, CURLOPT_COOKIEFILE, $config->getCookiesStorageFile());
     }
     if ($config->getMaxRedirects()) {
         curl_setopt($curlConnection, CURLOPT_MAXREDIRS, $config->getMaxRedirects());
     }
     if ($config->hasHeaders()) {
         curl_setopt($curlConnection, CURLOPT_HTTPHEADER, $this->processHeaders($config->getHeaders()));
     }
     if ($config->getPostData()) {
         curl_setopt($curlConnection, CURLOPT_POST, true);
         curl_setopt($curlConnection, CURLOPT_POSTFIELDS, $config->getPostData()->getRawPostDataString());
     }
     $data = curl_exec($curlConnection);
     curl_close($curlConnection);
     if ($data === false) {
         throw new EmptyResponseException();
     }
     $responses = $this->responseParser->extract($data);
     return new ResponsesContainer($responses);
 }