Php 调用MediaWiki API时,我只得到'+\';作为csrf令牌

Php 调用MediaWiki API时,我只得到'+\';作为csrf令牌,php,mediawiki,Php,Mediawiki,我可以使用简单令牌“+\”进行编辑,但使用这个简单令牌,我只能作为未注册的IP进行编辑,而不能作为注册用户进行编辑。有人能帮我吗 我的PHP代码: $parameters = array('action' => 'query', 'meta' => 'tokens', 'format' => 'json'); $options = array( 'http' => array( 'header' => "Content-type: applica

我可以使用简单令牌“+\”进行编辑,但使用这个简单令牌,我只能作为未注册的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";

您需要登录才能获得真正的CSRF令牌。有关如何登录的详细信息,请参阅:

请注意,保持登录需要跨请求存储cookie。使用
文件获取内容()
将很难做到这一点;建议将cURL与cookie jar一起使用。

若要获得一个cookie jar,请使用
type=login
参数。例如:

curl'https://www.mediawiki.org/w/api.php?action=query&meta=tokens&format=json&type=login'

我建议对这类事情使用cURL。使它更干净并为您处理所有协议内容。我尝试过不使用cURL,但它不起作用:“http'=>array('header'=>”内容类型:application/x-www-form-urlencoded\r\n Set Cookie:$cookieprefix=$sessionid;\r\n dewikiUserName=$lgname;\r\n dewikiToken=$token“,'method'=>POST','Content'=>http\u build\u query”($parameters),@MISHA004肯定不行-客户端头应该是
Cookie
,而不是
Set Cookie