i was trying to log in into a site which has the following API:
POST https://www.Thesite.com/Account/LogOn
post JSON data:{UserName:xxx,Pasword:xxx,SecondFactor:[optional]}
save the CookieContainer
& header["SecretKey"]
to pass for next calls, else you will get 409 conflict
I wrote the following Ruby script, but the response is : enter username and password
what is wrong?
!/usr/bin/env ruby
require "rubygems"
require "httparty"
include HTTParty
class TheSite
base_uri 'https://www.Thesite.com'
def initialize(u, p)
@data = {:UserName => u, :Pasword => p}.to_json
response = self.class.get('/Account/LogOn')
response = self.class.post(
'/Account/LogOn',
:data => @data,
:headers=>{'SecretKey'=>response.headers['Set-Cookie']})
@cookie = response.request.options[:headers]['cookie']
puts response
end
end
thesite = Thesite.new('myuser', 'mypassword')