Search This Blog

Thursday, March 15, 2018

Ruby Rails Rest-Client with POST Parameters, Authorization, Headers

response = RestClient::Request.new({
      method: :post,
      url: 'https://infovijay.com,
      user: 'vijay',
      password: 'dr12345',
      payload: { key1: 'value1', key2: 'value2' },
      headers: { :accept => :json, content_type: :json }
    }).execute do |response, request, result|
      case response.code
      when 400
        [ :error, parse_json(response.to_str) ]
      when 200
        [ :success, parse_json(response.to_str) ]
      else
        fail "#{response.to_str}."
      end
    end

1 comment:

Manisha said...

It seems you are a computer geek. Keep it up.

Hit Counter


View My Stats