我正在尝试使用以下PHP curl请求登录用户并将会话保存到cookie文件中:
curl -c cookie-jar.txt -v --header“X-CSRF-Token:unsafe”--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请求参数以添加它?