public function open()
    {
        $url = $this->url;
        $headers = [];

        // Set query data if there is any
        if (count($this->fields) > 0) {
            if ($this->method == 'GET') {
                $url = $this->options[CURLOPT_URL].'?'.$this->getQuery();
                $this->setOption(CURLOPT_URL, $url);
            } else {
                if (isset($this->requestHeaders['Content-Type']) && ($this->requestHeaders['Content-Type'] != 'multipart/form-data')) {
                    $this->setOption(CURLOPT_POSTFIELDS, $this->getQuery());
                    $this->setRequestHeader('Content-Length', $this->getQueryLength());
                } else {
                    $this->setOption(CURLOPT_POSTFIELDS, $this->fields);
                }
                $this->setOption(CURLOPT_POSTFIELDS, $this->fields);
                $this->setOption(CURLOPT_URL, $url);
            }
        }

        if ($this->hasRequestHeaders()) {
            foreach ($this->requestHeaders as $header => $value) {
                $headers[] = $header.': '.$value;
            }
            $this->setOption(CURLOPT_HTTPHEADER, $headers);
        }

        $this->response = curl_exec($this->resource);

        if ($this->response === false) {
            $this->throwError('Error: '.curl_errno($this->resource).' => '.curl_error($this->resource).'.');
        }

        return $this;
    }