Perform an HTTP request
543766
def request(method, path, options, headers)
      headers.merge!({
        'User-Agent' => user_agent
      })

      options.merge!({
        :api_key => api_key
      })

      response = connection.send(method) do |request|
        request.url "#{endpoint}#{path}", options
        request.body = options
        request.headers = headers
      end
      Shirtsio::Utils.handle_api_error(response) if response.status != 200

      Shirtsio::Utils.parse_json(response.body)[:result]
    end
729601
async def _request(
            self,
            method: str,
            url: str,
            *,
            headers: dict = None,
            params: dict = None,
            json: dict = None) -> dict:
        """"""
        full_url = '{0}/{1}'.format(url, self.zip_code)
        pieces = urlparse(url)

        if not headers:
            headers = {}
        headers.update({
            'Content-Type': 'application/json',
            'Referer': '{0}://{1}'.format(pieces.scheme, pieces.netloc),
            'User-Agent': API_USER_AGENT
        })

        async with self._websession.request(method, full_url, headers=headers,
                                            params=params, json=json) as resp:
            try:
                resp.raise_for_status()
                data = await resp.json(content_type=None)
                return data
            except client_exceptions.ClientError as err:
                raise RequestError(
                    'Error requesting data from {0}: {1}'.format(url, err))
1252051
def _make_request(self, conf, post_params={}):
        """"""
        endpoint, requires_auth = conf

        # setup the url and the request objects
        url = '%s%s.php' % (self.api_url, endpoint)
        log.debug('Setting url to %s' % url)
        request = urllib2.Request(url)

        # tack on authentication if needed
        log.debug('Post params: %s' % post_params)
        if requires_auth:
            post_params.update({
                'user': self.username,
                'pass': self.password
            })

        # url encode all parameters
        data = urlencode(post_params).encode('utf-8')

        # gimme some bitcoins!
        try:
            log.debug('Requesting data from %s' % url)
            response = urllib2.urlopen(request, data)
            return json.loads(response.read())
        except urllib2.URLError as e:
            log.debug('Full error: %s' % e)
            if hasattr(e, 'reason'):
                self.log.error('Could not reach host. Reason: %s' % e.reason)
            elif hasattr(e, 'code'):
                self.log.error('Could not fulfill request. Error Code: %s' % e.code)
            return None
881603
def perform
      http = Net::HTTP.new(uri.host, uri.port)
      http.use_ssl = true
      http.ssl_timeout = @options[:ssl_timeout] unless @options[:ssl_timeout].nil?
      http.open_timeout = @options[:open_timeout] unless @options[:open_timeout].nil?
      http.read_timeout = @options[:read_timeout] unless @options[:read_timeout].nil?

      req = Net::HTTP::Post.new(uri.request_uri, headers)
      req.body = body
      resp = http.request(req)
      verify_response(resp)

      resp
    end
615060
def request(self, method, url, body=None, content_type='application/json'):
        """"""
        headers = self.make_auth_headers(content_type)
        connection = http_client.HTTPSConnection(self.apibase)
        connection.request(method, url, body, headers=headers)
        response = connection.getresponse()
        data = response.read()
        connection.close()
        if response.status not in [200, 201]:
            raise SauceException('{}: {}.\nSauce Status NOT OK'.format(
                response.status, response.reason), response=response)
        return json.loads(data.decode('utf-8'))
797966
def perform_request(method, uri, options={})
      f = Fiber.current

      target_uri = endpoint + uri

      headers = {}
      unless options.fetch(:no_login, false)
        headers['authorization'] = auth_provider.auth_header
      end

      http = EM::HttpRequest.new(target_uri).send(method.to_sym, :head => headers)

      http.callback { f.resume(http) }
      http.errback  { f.resume(http) }

      Fiber.yield

    rescue URI::Error
      raise DirectorError, "Invalid URI: #{target_uri}"
    end
1291881
def make_request(self, session, url, **kwargs):
        
        log.debug('Making request: POST %s %s' % (url, kwargs))
        return session.post(url, **kwargs)
61344
def request(self, method, url, body=None, headers={}):
        """"""
        self._send_request(method, url, body, headers)
59472
def _do_request(self, request, url, **kwargs):
        ""
        try:
            response = request(url, stream=True, **kwargs)
        except RequestException as e:
            raise RequestError(e)
        else:
            if response.status_code >= 400:
                raise ResponseError(response)
        # Try to return the response in the most useful fashion given it's
        # type.
        if response.headers.get('content-type') == 'application/json':
            try:
                # Try to decode as JSON
                return response.json()
            except (TypeError, ValueError):
                # If that fails, return the text.
                return response.text
        else:
            # This might be a file, so return it.
            if kwargs.get('params', {}).get('raw', True):
                return response.raw
            else:
                return response
675358
def do_request(self, request, proxies, timeout, **_):
        """"""
        print('{0} {1}'.format(request.method, request.url))
        response = self.http.send(request, proxies=proxies, timeout=timeout,
                                  allow_redirects=False)
        response.raw = None  # Make pickleable
        return response
1067293
function httpRequest(path, req, options)
{
    return new Promise(function(resolve, reject) {
        req = extend({}, defaults, req, options);
        req.url += path;

        request(req, function(error, response, body) {
            if (error || !(/^2/.test('' + response.statusCode)) || /action=".?login.lua"/.test(body)) {
                if (/action=".?login.lua"/.test(body)) {
                    // fake failed login if redirected to login page without HTTP 403
                    response.statusCode = 403;
                }
                reject({
                    error: error,
                    response: response,
                    options: req
                });
            }
            else {
                resolve(body.trim());
            }
        });
    });
}
1241431
def _request(self, function, params, method='POST', headers={}):
        """"""
        
        if method is 'POST':
            params = urllib.parse.urlencode(params)
            headers = { "Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain" }
        
        path = '/%s/%s' % (self._version, function)
        
        self._conn.request(method, path, params, headers)
        return self._conn.getresponse()
949365
def _request(self, method, url, params=None, headers=None, data=None):
        """"""
        if not params:
            params = {}

        # set default headers
        if not headers:
            headers = {
                'accept': '*/*'
            }
            if method == 'POST' or method == 'PUT':
                headers.update({'Content-Type': 'application/json'})
        try:
            response = requests.request(method=method, url=self.host + self.key + url, params=params,
                                        headers=headers, data=data)

            try:
                response.raise_for_status()

                response_code = response.status_code
                success = True if response_code // 100 == 2 else False
                if response.text:
                    try:
                        data = response.json()
                    except ValueError:
                        data = response.content
                else:
                    data = ''

                response_headers = response.headers

                return BurpResponse(success=success, response_code=response_code, data=data,
                                    response_headers=response_headers)
            except ValueError as e:
                return BurpResponse(success=False, message="JSON response could not be decoded {}.".format(e))
            except requests.exceptions.HTTPError as e:
                if response.status_code == 400:
                    return BurpResponse(success=False, response_code=400, message='Bad Request')
                else:
                    return BurpResponse(
                        message='There was an error while handling the request. {}'.format(response.content),
                        success=False)
        except Exception as e:
            return BurpResponse(success=False, message='Eerror is %s' % e)
1215484
def _request(self, path, method, body=None):
        """"""
        url = '/'.join([_SERVER, path])
        (resp, content) = _HTTP.request(url, method,
                                        headers=self._headers, body=body)

        content_type = resp.get('content-type')
        if content_type and content_type.startswith('application/json'):
            content = json.loads(content.decode('UTF-8'))

        return (resp, content)
252032
def http_request(url)
      url = URIParser.new(url).with_scheme

      CLI.put_header(url)
      CLI.log "Beginning HTTP request for #{url}"
      response = HTTParty.get(url, headers: { "User-Agent" => "news-scraper-#{NewsScraper::VERSION}" })

      raise ResponseError.new(
        error_code: response.code,
        message: response.message,
        url: url
      ) unless response.code == 200

      CLI.log "#{response.code} - #{response.message}. Request successful for #{url}"
      CLI.put_footer

      if block_given?
        yield response
      else
        response
      end
    end
1164585
async def request(self, method, path, json=None, auth=True):
        """"""
        url = 'http://{}/api/'.format(self.host)
        if auth:
            url += '{}/'.format(self.username)
        url += path

        try:
            async with self.websession.request(method, url, json=json) as res:
                if res.content_type != 'application/json':
                    raise ResponseError(
                        'Invalid content type: {}'.format(res.content_type))
                data = await res.json()
                _raise_on_error(data)
                return data
        except client_exceptions.ClientError as err:
            raise RequestError(
                'Error requesting data from {}: {}'.format(self.host, err)
            ) from None
27383
def request(self, url, method, data=None, headers=None):
        
        http_headers = merge_dict(self.default_headers, headers or {})
        request_data = merge_dict({'api_key': self.apikey}, data or {})

        logger.info('HTTP %s REQUEST TO %s' % (method, url))

        start = datetime.datetime.now()

        try:
            response = requests.request(method=method, url=url, data=json.dumps(request_data),
                                        headers=http_headers)
        except exceptions.BadRequestError as e:
            return json.loads({'errors': e.content})

        duration = datetime.datetime.now() - start

        logger.info('RESPONSE %s DURATION %s.%s' % (response.encoding, duration.seconds,
                                                    duration.microseconds))

        return json.loads(response.content) if response.content else {}