我正在尝试使用以下 PHP curl 请求登录用户并将会话保存到 cookie 文件中:
curl -c cookie-jar.txt -v --header "X-CSRF-Token: 不安全" --data "xs-username={{USER}}&xs-password={{PASS}}" " https:// .../login.func "
在 PHP 中有以下代码:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://.../login.func');
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username={{USER}}&password={{PASS}}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies/cookie-jar.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE,'cookies/cookie-jar.txt');
$headers[] = 'X-CSRF-Token:' . 'unsafe';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$answer = curl_exec($ch);
if (curl_error($ch)) {
echo curl_error($ch);
}
但是,执行此操作时出现错误:
由于 XSRF 令牌丢失或无效,请求执行失败。如何修改我的 curl 请求参数以添加它?