调用 MediaWiki-API 时,我只得到 '+\' 作为 csrf-token

Mic*_*fer 6 php mediawiki

我可以使用简单的令牌 '+\' 进行编辑,但使用这个简单的令牌,我只能作为未注册的 IP 进行编辑,而不能作为注册用户进行编辑。有人能帮我吗?

我的PHP代码:

$parameters = array('action' => 'query', 'meta' => 'tokens', 'format' => 'json');
$options = array(
   'http' => array(
      'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
      'method'  => 'POST',
      'content' => http_build_query($parameters),
    ),
);
$context  = stream_context_create($options);
$result = file_get_contents($wiki, false, $context);
echo "$result";
Run Code Online (Sandbox Code Playgroud)

小智 3

您需要登录才能获取真正的 CSRF 令牌。详细登录方法请参见:

http://www.mediawiki.org/wiki/API:登录

请注意,保持登录状态需要您跨请求存储 cookie。这会很困难file_get_contents();建议将 cURL 与 cookie jar 一起使用。