要获得网站https://app.guardsaas.com上的授权,我需要:
发出POST请求https://app.guardsaas.com/login_check 带有参数:
'_ username'=登录 '_password'=通过 '_remember_me'='开启' '_csfr_token'=来自第1页的令牌
我编写了一个脚本,该脚本首先获取令牌,然后在站点的帮助下被授权,但是它不起作用,该错误可以用SSL,Cookie覆盖,并尝试了一堆不同的选项-没什么出来
我的代码:
require "net/http"
require 'net/https'
require "uri"
uri = URI('https://app.guardsaas.com/login')
token = ""
text = ""
http = Net::HTTP.start(uri.host, uri.port,
:use_ssl => uri.scheme == 'https',
:verify_mode => OpenSSL::SSL::VERIFY_NONE)
# make a request to get the server's cookies
response = http.get('https://app.guardsaas.com/login')
puts response.code
if (response.code == '200')
all_cookies = response.get_fields('set-cookie')
cookies_array = Array.new
all_cookies.each { | cookie |
cookies_array.push(cookie.split('; ')[0])
}
cookies = cookies_array.join('; ')
text = response.body.to_s
st = text.index('_csrf_token" value=').to_i
token = text[st+20..st+19+40]
puts "token: " + token
data = {
"_username" => 'login',
"_password" => 'pass',
"_remember_me" => 'on',
"_csrf_token" => token
}
data = URI.encode_www_form(data)
headers = {
'Cookie' => cookies,
'Referer' => 'https://app.guardsaas.com',
'Content-Type' => 'application/x-www-form-urlencoded'
}
headers = URI.encode_www_form(headers)
data = http.post('https://app.guardsaas.com/login_check', data, headers)
puts data.body
end