我可以使用简单的令牌“+\”进行编辑,但是使用这个简单的令牌,我只能作为未注册的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";发布于 2015-02-16 21:27:03
您需要登录才能获得真正的CSRF令牌。有关如何登录的详细信息,请参阅:
http://www.mediawiki.org/wiki/API:Login
请注意,保持登录将需要跨请求存储cookie。对于file_get_contents()来说,这将是很困难的;建议在cookie jar中使用cURL。
发布于 2020-08-10 04:24:25
要获得登录令牌,请使用type=login参数。示例:
curl 'https://www.mediawiki.org/w/api.php?action=query&meta=tokens&format=json&type=login'https://stackoverflow.com/questions/28549519
复制相似问题