简体   繁体   中英

post request to mediawiki api

I'm trying to post data to the mediawiki API and it's not recognising the token I am sending.

var data = querystring.stringify({
      action: "createaccount",
      name: "sean",
      email: "xxx",
      password: "test",
      token: "66cde5ad831521fe9d0fe4df3a2db25f"
});

var options = {
    host: '54.201.91.132',
    port: 80,
    path: '/wiki/api.php',
    method: 'POST',
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Content-Length': Buffer.byteLength(data)
    }
};

var req = http.request(options, function(res) {
    res.setEncoding('utf8');
    res.on('data', function (chunk) {
        console.log("body: " + chunk);
    });
});

req.write(data);
req.end();

I have tried sending the same data using the Postman chrome extension and this works fine.

POST /wiki/api.php HTTP/1.1
Host: 54.201.91.132
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
 action=createaccount&name=shamus&email=xxx&password=test&token=5dc9c943ac3255f87dc7782c24f61ac6&format=json

{
"createaccount": {
    "username": "Shamus",
    "userid": 22,
    "token": "c3744c0f19ea62f6baf89b10f7c86f7f",
    "result": "success"
}
}

Any ideas what I'm doing wrong?

In addition to token, you must pass it the cookies you received with it. Of course, the token must not be hardcoded and be acquired dynamically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM