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
Post a Comment

Hit Counter


View My Stats