php - CURL 登录到使用令牌的页面
问题描述
我正在使用 php curl 尝试登录到使用令牌的表单。我尝试了不同的组合,其中一些来自 StackOverflow,但似乎无法做到正确。
到目前为止,这是我的代码:
$html = new simple_html_dom();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.example.de/My-account');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, '');
$response = curl_exec($ch);
$html->load($response);
foreach($html->find('input[name="jtl_token"]') as $content){
$token = $content->value;
}
$credentials = [
'jtl_token' => $token,
'email' => 'my@email.com',
'passwort' => 'password',
'login' => 1
];
curl_setopt($ch, CURLOPT_URL, 'https://www.example.de/My-account');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($credentials));
curl_setopt($ch, CURLOPT_COOKIEFILE, '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
echo $response;
我正在使用simple_html_dom
类来获取令牌,然后我只是尝试将其发送到该页面但它不起作用,响应是登录前的页面。
谢谢你。
解决方案
推荐阅读
- powershell - 用于播放音乐的 Powershell 脚本
- android - 图库视频缩略图在android recyclerview中加载非常慢
- javascript - AWS S3 使用预签名 URL 更新映像(Axios-PUT 请求)
- python - 如何激活名称中带有空格的 conda 环境?
- sql - UNION 将 6 个不同表中的列总和合并为一列?
- jekyll - Jekyll 内容在页面上重复
- docker - 在容器 CLI 中,如何使用 Sublime 文本?
- php - PHP 命名空间问题
- typescript - 没有库的 HTML CANVAS 5 中的水平条形图
- jax-rs - Jersey 2 和 Spring Boot - 无法在 Provider 上使用 @Context 进行注入