2014-02-19 47 views
0

我試圖將數據發佈到mediawiki API,但它不能識別我發送的令牌。對mediawiki API的發佈請求

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(); 

我已經嘗試發送相同的數據使用郵遞員鉻擴展,這工作正常。

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" 
} 
} 

任何想法我做錯了什麼?

+0

你從哪裏得到令牌? – Bergi

回答

1

除了令牌之外,您還必須將它隨附的cookie傳遞給它。當然,令牌不能被硬編碼和動態獲取。