如何使用rest-client gem发送标头和cookie

时间:2015-08-06 12:47:48

标签: ruby-on-rails ruby cookies rest-client

在Code中,我试图在同一个请求中发送标头和cookie 下面是代码

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

我收到以下错误消息

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

2 个答案:

答案 0 :(得分:1)

Cookie是标题的一部分。这里是RestClient

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

请参阅https://github.com/rest-client/rest-client/blob/master/lib/restclient/request.rb

中的initialize方法

这样做 -

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

答案 1 :(得分:0)

尝试

=SUMIFS(B:B,A:A,"="&A2,C:C,"="&C2,D:D,"="&D2)