ruby - 使用 SSL、cookie、标头在站点上进行身份验证 - 不起作用
问题描述
对于网站https://app.guardsaas.com上的授权,我需要:
- 打开https://app.guardsaas.com/login并获取值“_csrf_token”
使用参数发出 POST 请求https://app.guardsaas.com/login_check :
'_username' = login '_password' = pass '_remember_me' = 'on' '_csfr_token' = 来自 p.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
解决方案
推荐阅读
- r - Geom_vline() 不会在 ggplot 上显示
- sql - SQL 查询结构是否会影响其性能?
- ubuntu-18.04 - PermissionError:[Errno 13] 权限被拒绝:'/opt/stack/.cache/pip/wheels/a7/c1/ea/cf5bd31012e735dc1dfea3131a2d5eae7978b251083d6247bd'
- php - 为什么这段代码没有将任何内容写入数据库?
- node.js - 无法将反应中的数据发布到 node.ks 空体`{}`
- c# - StackPanel 中的 WebBrowser 不会扩展到其在 WPF 中的内容大小
- python-3.x - 使用 popen 与 python 交互式 shell 交互
- javascript - browser-sync 不会从 gulp 刷新页面
- html - 为什么我的图像不在一个列中?我在这里做错了什么?
- pytorch - 如何从输入 ID 中获取填充掩码?