javascript - 如何发出登录请求以登录 https://analytics.oag.com/analyser-client/home(Javascript 网站)
问题描述
我尝试使用命令卷曲
curl 'https://analytics.oag.com/analyser-client/home' -H 'Accept-Language:
en-US,en;q=0.9' -H 'Connection: keep-alive' -H 'Accept-Language: en-
US,en;q=0.9' -H 'Host: analytics.oag.com' -H 'User-Agent: Mozilla/5.0
(Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/66.0.3359.181 Safari/537.36' -H 'Content-Type: text/html;charset=UTF-
8' --data '{"username":"test","password":"test"}'
但它似乎不起作用......不知道我错过了哪些部分......关于如何登录这个网站的任何想法?
解决方案
Not sure what parts am I missing
- 您缺少 cookie 会话 id、referer 标头和X-Requested-With: XMLHttpRequest
标头,并且您的 Content-Type 标头是错误的(应该是Content-Type: application/json
),如果您在没有 cookie 会话的情况下访问它,登录页面也会自动加载两次(首先它会获得一个 cookie 会话,然后它会自行刷新),您可能应该按照套件登录。您特别提到了 python,我不知道如何在 python 中执行此操作,但这是我在 PHP 中使用hhb_curl执行此操作的方式:
<?php
declare(strict_types = 1);
require_once ('hhb_.inc.php');
$hc = new hhb_curl ( '', true );
// getting cookie session and refresh (dunno why we need to refresh, but the login page javascript is doing it, so follow suite)
$hc->exec ( 'https://analytics.oag.com/analyser-client/home' )->exec ( 'https://analytics.oag.com/analyser-client/home' );
$response = $hc->setopt_array ( array (
CURLOPT_POST => 1,
CURLOPT_URL => 'https://analytics.oag.com/analyser-client/broker-services/login/validate',
CURLOPT_HTTPHEADER => array (
'Content-Type: application/json',
'Origin: https://analytics.oag.com', // i don't think curl set this header this automatically
'X-Requested-With: XMLHttpRequest'
),
CURLOPT_POSTFIELDS => json_encode ( array (
'username' => 'username?',
'password' => 'password?'
) )
) )->exec ()->getResponseBody ();
var_dump ( $response );
$parsed = @json_decode ( $response, true );
if (empty ( $parsed ) || $parsed ['status'] === 'ERROR') {
throw new \RuntimeException ( 'failed to login! ' . $response );
}
推荐阅读
- java - 对 .txt 文件中的行进行分组
- node.js - TypeError:无法读取未定义的属性“q1”
- reactjs - ReactJS 模块构建失败:SyntaxError: Unexpected token
- javascript - JS getElementsByClassName() 不适用于具有相同类的多个元素
- android - 带有动画的圆形进度指示器
- ios - 在视图控制器中获取已关闭 PopupDialog 的通知
- javascript - 带有 lxml 的 Xpath 中没有元素:Javascript 生成的页面
- botframework - LUIS 模型是否有最大意图数?和/或是否有推荐的最大值?
- react-native - 在 React Native Navigation 中更改“SingleScreenApp”的主屏幕
- unit-testing - 对来自 package.json 的文件夹中的文件夹运行测试