How to send header and cookies using a rest-client click

In code i am trying to send both header and cookies in the same request below is the code

 @result = RestClient.post(
              'url',
              {:billingSourceCode => "code"},
              {:cookies => {:session_id => "1234"}},
              {:headers => {'Content-Type' =>'application/json', 
                           "Authorization" => "key",  
                           "Accept" => "application/json"}})

      

I am getting below error message

ArgumentError (wrong number of arguments (4 for 3)):

      

+3


source to share


2 answers


Try



RestClient::Request.execute(
      method: :post,
      url: 'whatever',
      cookies: {:session_id => "1234"},
      headers: {'Content-Type' =>'application/json',
                      "Authorization" => "key",
                      "Accept" => "application/json"})

      

0


source


Cookies are part of the headers. Here in RestClient

:

    @cookies = @headers.delete(:cookies) || args[:cookies] || {}

      

See method initialize

at https://github.com/rest-client/rest-client/blob/master/lib/restclient/request.rb



Do it -

@result = RestClient.post(
          'url',
          {:billingSourceCode => "code"},
          {:headers => {'Content-Type' =>'application/json', 
                       "Authorization" => "key",  
                       "Accept" => "application/json"},
                       {:cookies => {:session_id => "1234"}}
          })

      

0


source







All Articles