protected function request($url, $options = array(), $acceptheader = 'application/json') {
        $murl = new moodle_url($url);

        if ($this->accesstoken) {
            if ($this->use_http_get()) {
                // If using HTTP GET add as a parameter.
                $murl->param('access_token', $this->accesstoken->token);
            } else {
                $this->setHeader('Authorization: Bearer '.$this->accesstoken->token);
            }
        }

        if ($acceptheader) {
            $this->setHeader('Accept: ' . $acceptheader);
        }

        $response = parent::request($murl->out(false), $options);

        $this->resetHeader();

        return $response;
    }