public function connect() { $this->open(); $sendData = $this->serializeParams($this->getParameters()); curl_setopt($this->curl, CURLOPT_URL, "{$this->url}?{$sendData}"); //curl_setopt($this->curl, CURLOPT_POST, true); // HTTP POST //curl_setopt($this->curl, CURLOPT_POSTFIELDS, $sendData); $response = curl_exec($this->curl); if ($response === false) { $errno = @curl_errno($this->curl); $error = @curl_strerror($errno); $this->close(); throw TransferException::couldNotTransferData($this->url . ($this->isProxy() ? ' (usando proxy)' : ''), "[{$errno}] {$error}"); } list($response_headers_str, $response) = explode("\r\n\r\n", $response); /*$response_headers = $this->_readHeaders($response_headers_str); if (!$this->checkResponseToken($response_headers['X-FW-Response'])) { throw new WrongDataTransferException('Resposta inv�lida do servidor, entre em contato com a Furac�o'); }*/ $this->close(); if (empty($response)) { throw TransferException::emptyDataReturned(); } return $response; }
public function connect() { $this->open(); try { if (!$this->getFunction()) { throw TransferException::functionMandatory(); } $response = $this->soapClient->__call($this->getFunction(), $this->getParameters()); /*$response_headers_str = $this->pointer->__getLastResponseHeaders(); $response_headers = $this->_readHeaders($response_headers_str); if (!$this->checkResponseToken($response_headers['X-FW-Response'])) { throw new WrongDataTransferException('Resposta inv�lida do servidor, entre em contato com a Furac�o'); }*/ } catch (TransferException $e) { throw $e; // se for exception de transfer, lançar do jeito que está } catch (\Exception $e) { throw TransferException::couldNotTransferData($this->url . ($this->isProxy() ? ' (usando proxy)' : ''), $e->getMessage()); } $this->soapClient = null; if (empty($response)) { throw TransferException::emptyDataReturned(); } return $response; }
public function connect() { $sendData = $this->serializeParams($this->getParameters()); $context = stream_context_create(array('http' => array('timeout' => $this->timeout, 'header' => "X-Fw-Transfer: file\r\n"))); $response = @file_get_contents("{$this->url}?{$sendData}", false, $context); if ($response === false) { throw TransferException::unknownError(); } if (empty($response)) { throw TransferException::emptyDataReturned(); } return $response; }
public function connect() { $this->normalizeUrl(); $this->open(); $sendData = $this->serializeParams($this->getParameters()); $headers = array(); if ($this->isProxy()) { //$headers[] = "POST $this->url HTTP/1.1"; $headers[] = "GET {$this->url}?{$sendData} HTTP/1.1"; $headers[] = "Host: {$this->proxyHost}"; if ($this->isAuthProxy()) { $headers[] = "Proxy-Authorization: Basic " . base64_encode("{$this->proxyLogin}:{$this->proxyPass}"); } } else { //$headers[] = "POST $this->uri HTTP/1.1"; $headers[] = "GET {$this->uri}?{$sendData} HTTP/1.1"; $headers[] = "Host: {$this->host}"; } //$headers[] = "X-FW-Token: " . $this->getToken(); $headers[] = "X-FW-Transfer: socket"; $headers[] = "Content-Type: application/x-www-form-urlencoded"; $headers[] = "Content-Length: " . strlen($sendData); $headers[] = "Connection: close"; $headers[] = ""; // enter necessario $headers[] = $sendData; // dados a serem passados $header_data = implode("\r\n", $headers); // manda no stream o header com os dados fwrite($this->sck, $header_data); // le primeiro o header de response do { $responseHeader .= fread($this->sck, 1); } while (!preg_match('/\\r\\n\\r\\n$/', $responseHeader)); // depois le o conteudo do response if (!strstr($responseHeader, "Transfer-Encoding: chunked")) { // se nao veio chunkado, ler tudo $response = ''; while (!feof($this->sck)) { $response .= fgets($this->sck, 128); } } else { // veio chunkado, ler os pedaços $response = ''; while ($chunk_length = hexdec(fgets($this->sck))) { $response_chunk = ''; $read_length = 0; while ($read_length < $chunk_length) { $response_chunk .= fread($this->sck, $chunk_length - $read_length); $read_length = strlen($response_chunk); } $response .= $response_chunk; fgets($this->sck); } } $response = chop($response); $this->close(); if (empty($response)) { throw TransferException::emptyDataReturned(); } return $response; }