无法获取 MediaWiki api 的编辑令牌

发布于 2024-12-25 21:22:56 字数 1240 浏览 1 评论 0原文

我无法获得 MediaWiki 的编辑令牌:

请求

POST /w/api.php HTTP/1.1
Host: en.wikipedia.org
Accept: */*
User-agent: Sbose7890
Content-Length: 59
Content-Type: application/x-www-form-urlencoded

action=query&prop=info&intoken=edit&titles=Java&format=json 

响应

HTTP/1.0 200 OK
Date: Tue, 10 Jan 2012 09:14:03 GMT
Server: Apache
X-Content-Type-Options: nosniff
Cache-Control: private
Vary: Accept-Encoding
Content-Length: 209
Content-Type: application/json; charset=utf-8
X-Cache: MISS from sq34.wikimedia.org
X-Cache-Lookup: MISS from sq34.wikimedia.org:3128
X-Cache: MISS from sq59.wikimedia.org
X-Cache-Lookup: MISS from sq59.wikimedia.org:80
Connection: close

{
  "query": {
    "pages": {
      "69336": {
        "starttimestamp": "2012-01-10T09:14:03Z",
        "lastrevid": 469959190,
        "touched": "2012-01-07T11:38:04Z",
        "pageid": 69336,
        "title": "Java",
        "edittoken": "+\\",
        "ns": 0,
        "length": 37800,
        "counter": ""
      }
    }
  }
}

我使用 hurl.it

我也登录了。

I'm not being able to obtain an edit token for MediaWiki:

Request

POST /w/api.php HTTP/1.1
Host: en.wikipedia.org
Accept: */*
User-agent: Sbose7890
Content-Length: 59
Content-Type: application/x-www-form-urlencoded

action=query&prop=info&intoken=edit&titles=Java&format=json 

Response

HTTP/1.0 200 OK
Date: Tue, 10 Jan 2012 09:14:03 GMT
Server: Apache
X-Content-Type-Options: nosniff
Cache-Control: private
Vary: Accept-Encoding
Content-Length: 209
Content-Type: application/json; charset=utf-8
X-Cache: MISS from sq34.wikimedia.org
X-Cache-Lookup: MISS from sq34.wikimedia.org:3128
X-Cache: MISS from sq59.wikimedia.org
X-Cache-Lookup: MISS from sq59.wikimedia.org:80
Connection: close

{
  "query": {
    "pages": {
      "69336": {
        "starttimestamp": "2012-01-10T09:14:03Z",
        "lastrevid": 469959190,
        "touched": "2012-01-07T11:38:04Z",
        "pageid": 69336,
        "title": "Java",
        "edittoken": "+\\",
        "ns": 0,
        "length": 37800,
        "counter": ""
      }
    }
  }
}

I tried it out using hurl.it.

I'm also logged in.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

纵情客 2025-01-01 21:22:56

您将获得一个编辑令牌:+\。这是针对匿名用户的,并且始终相同。请参阅 mw:Manual:编辑令牌,以及从那里链接的修订版本。

问题是,无论您是否登录,hurl 都必须登录。它必须发送一个有效的 enwiki_session cookie,例如您的。但不要发布你的,每个人都可以用它登录!

You are getting an edit token: +\. This is the one for anon users, and is always the same. See mw:Manual:Edit token, and also the revisions linked from there.

The problem is that it's regardless of your login, hurl must be logged in. It would have to send a valid enwiki_session cookie, yours for example. But do not publish yours, everybody could login with it!

生活了然无味 2025-01-01 21:22:56

简而言之,不要使用原始 MediaWiki API每个都有客户端可以想象的语言可以为您处理所有这些乏味的事情。例如,如果您使用 Ruby,这里是您需要的所有 MediaWiki::Gateway 代码登录并编辑文章:

mw = MediaWiki::Gateway.new(your-wiki)
mw.login(user, pw)
mw.create("Article", "Hello world")

In short, do not use the raw MediaWiki API, there are clients for every conceivable language out there which take care of all this tedious stuff for you. For example, if you're using Ruby, here's all the MediaWiki::Gateway code you need to log in and edit an article:

mw = MediaWiki::Gateway.new(your-wiki)
mw.login(user, pw)
mw.create("Article", "Hello world")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文