Use this method to setup your request's payload and headers.

 Example:

   request.set :headers do |h|
     h.content_type = 'application/ufo'
   end

   request.set :params do |p|
     p.sessionid = '12323'
     p.api_key   = '13123
   end
969578
def set(container, &declarations)
      struct = OpenStruct.new
      declarations.call(struct)
      send("#{container}=", struct.table)
    end
807490
def request(method, path, params={})
      headers = @default_headers.merge({'Authorization' => "Bearer #{@access_token}"})
      result = http_client.send_request(method, path, {
        :params  => params,
        :headers => headers
      })
      result
    end
679897
async def create_post_request(self, method: str, params: Dict = None):
        
        if params is None:
            params = {}
        headers = {"Content-Type": "application/json"}
        payload = {
            "method": method,
            "params": [params],
            "id": next(self.idgen),
            "version": "1.0",
        }

        if self.debug > 1:
            _LOGGER.debug("> POST %s with body: %s", self.guide_endpoint, payload)

        async with aiohttp.ClientSession(headers=headers) as session:
            res = await session.post(self.guide_endpoint, json=payload, headers=headers)
            if self.debug > 1:
                _LOGGER.debug("Received %s: %s" % (res.status_code, res.text))
            if res.status != 200:
                raise SongpalException(
                    "Got a non-ok (status %s) response for %s" % (res.status, method),
                    error=await res.json()["error"],
                )

            res = await res.json()

        # TODO handle exceptions from POST? This used to raise SongpalException
        #      on requests.RequestException (Unable to get APIs).

        if "error" in res:
            raise SongpalException("Got an error for %s" % method, error=res["error"])

        if self.debug > 1:
            _LOGGER.debug("Got %s: %s", method, pf(res))

        return res
610914
def __prepare_gprest_call(self, requestURL, params=None, headers=None, restType='GET', body=None):
        
        if self.__serviceAccount.is_iam_enabled():
            auth = None
            iam_api_key_header = {
                self.__AUTHORIZATION_HEADER_KEY: str('API-KEY '+self.__serviceAccount.get_api_key())
            }
            if not headers is None:
                headers.update(iam_api_key_header)
            else:
                headers = iam_api_key_header
        elif self.__auth == self.BASIC_AUTH:
            auth = (self.__serviceAccount.get_user_id(),
                    self.__serviceAccount.get_password())
        elif self.__auth == self.HMAC_AUTH:
            auth = None

            # need to prepare url by appending params to the end
            # before creating the hmac headers
            fakeRequest = requests.PreparedRequest()
            fakeRequest.prepare_url(requestURL, params=params)
            preparedUrl = fakeRequest.url

            hmacHeaders = self.__get_gaas_hmac_headers(method=restType,
                                                       url=preparedUrl, body=body)
            if not headers is None:
                headers.update(hmacHeaders)
            else:
                headers = hmacHeaders
        return auth, headers
544801
def set_headers(self):
        
        self.set_header("Accept-Ranges", "bytes")

        content_type = self.get_content_type()
        if content_type:
            self.set_header("Content-Type", content_type)
211429
def set(options)
      json_body = options.to_json
      request_uri = "#{base_request_uri}/state"
      HTTParty.put(request_uri, :body => json_body)
    end
709855
def request(self, request_path, data=None, do_authentication=True, is_json=True):
        
        uri = self.api_uri % request_path
        request = urllib2.Request(uri)

        # Build up the request
        if is_json:
            request.add_header("Content-Type", "application/json")
            if data is not None:
                request.add_data(json.dumps(data))
        elif data is not None:
            request.add_data(data)

        if do_authentication:
            if self.client_id is None or self.client_secret is None:
                raise Exception(u"You need to supply a client_id and client_secret to perform an authenticated request")
            basic_auth = base64.b64encode("%s:%s" % (self.client_id, self.client_secret))
            request.add_header("Authorization", "Basic %s" % basic_auth)

        try:
            response = self._make_request(request)
        except Exception as inst:
            raise # automatically re-raises the exception

        if 'status' in response:
            # Grab the status info if it exists
            self._last_status_code = response['status']['code']
            if 'message' in response['status']:
                self._last_status_message = response['status']['message']

            if 'data' in response:
                return response['data']

        return response
1363611
def _construct_request(self):
        
        if self.parsed_endpoint.scheme == 'https':
            conn = httplib.HTTPSConnection(self.parsed_endpoint.netloc)
        else:
            conn = httplib.HTTPConnection(self.parsed_endpoint.netloc)
        head = {
            "Accept": "application/json",
            "User-Agent": USER_AGENT,
            API_TOKEN_HEADER_NAME: self.api_token,
        }
        if self.api_version in ['0.1', '0.01a']:
            head[API_VERSION_HEADER_NAME] = self.api_version
        return conn, head
1351629
def prepare(self, params):
        
        jsonparams = json.dumps(params)
        payload = base64.b64encode(jsonparams.encode())
        signature = hmac.new(self.secret_key.encode(), payload,
                             hashlib.sha384).hexdigest()

        return {'X-GEMINI-APIKEY': self.api_key,
                'X-GEMINI-PAYLOAD': payload,
                'X-GEMINI-SIGNATURE': signature}
1071221
def set_request_defaults(endpoint, private_token, sudo=nil)
      raise Error::MissingCredentials.new("Please set an endpoint to API") unless endpoint
      @private_token = private_token

      self.class.base_uri endpoint
      self.class.default_params :sudo => sudo
      self.class.default_params.delete(:sudo) if sudo.nil?
    end
1216363
def make_request_body(opts, headers)
      case
      when opts.body
        opts.body
      when opts.form
        form = HTTP::FormData.create opts.form
        headers[Headers::CONTENT_TYPE] ||= form.content_type
        form
      when opts.json
        body = MimeType[:json].encode opts.json
        headers[Headers::CONTENT_TYPE] ||= "application/json; charset=#{body.encoding.name}"
        body
      end
    end
953211
def send_request(payload)
      response = @http.post payload
      raise APIError, response unless response.is_a?(Net::HTTPSuccess)
      response
    end
816081
def set_params(self, data):
        """"""
        bytes_io = BytesIO(data)

        assert struct.unpack("<I", bytes_io.read(4))[0] == 0xb5890dba

        self.nonce = bytes_io.read(16)
        self.server_nonce = bytes_io.read(16)

        self.g = struct.unpack("<I", bytes_io.read(4))[0]

        self.dh_prime = deserialize_string(bytes_io)
        self.g_a = deserialize_string(bytes_io)

        self.server_time = struct.unpack("<I", bytes_io.read(4))[0]
645621
def post(path, body = '', headers = {})
      headers = { 'Content-Type' => 'application/json' }.merge(headers)
      request(:post, path, body, merge_default_headers(headers))
    end
513311
def _put_request(self, url, headers, data=None):
        
        return self._session.put(url, headers=headers, data=data)
1363495
def request_payload(cls, request, request_id):
        ''''''
        payload = {
            'jsonrpc': '2.0',
            'method': request.method,
        }
        # A notification?
        if request_id is not None:
            payload['id'] = request_id
        # Preserve empty dicts as missing params is read as an array
        if request.args or request.args == {}:
            payload['params'] = request.args
        return payload
1088932
def prepare_request(self, method, url, body=''):
        
        headers = {
            'Content-type': 'application/json',
        }
        # Note: we don't pass body to sign() since it's only for bodies that
        # are form-urlencoded. Similarly, we don't care about the body that
        # sign() returns.
        uri, signed_headers, signed_body = self.oauth_client.sign(
            url, http_method=method, headers=headers)
        if body:
            if method == 'GET':
                body = urllib.urlencode(body)
            else:
                body = json.dumps(body)
        headers.update(signed_headers)
        return {"headers": headers, "data": body}