Media wiki second POST still returns NeedToken result

落花浮王杯 提交于 2020-01-06 08:30:19

问题


After first POST request I get "NeedToken" result then in my second POST request I pass token and sessionid as parameters. Here is my Javascript code:

function wiki_auth(login, pass, ref){
    $.post(ref+'api.php?action=login&lgname=' + login +
            '&lgpassword=' + pass + '&format=json', function(data) {
        if(data.login.result == 'NeedToken') {
            $.post(ref+'api.php?action=login&lgname=' + login +
                    '&lgpassword=' + pass + '&lgtoken='+data.login.token+'&format=json&sessionid='+data.login.sessionid+'&lgdomain='+ref,
                    function(data) {
                if(!data.error){
                   if (data.login.result == "Success") {
                        document.location.href=ref;
                   } else {
                        console.log('Result: '+ data.login.result);
                   }
                } else {
                   console.log('Error: ' + data.error);
                }
            });
        } else {
            console.log('Result: ' + data.login.result);
        }
        if(data.error) {
            console.log('Error: ' + data.error);
        }
    });
}

I am not sure if I need to pass something else as well.


回答1:


You will need to actually POST the parameters as data (in the body of the HTTP request), not append them to the GET parameters in the url. Use

$.post(ref+'api.php?action=login&format=json', {
    lgname: login,
    lgpassword: pass,
    lgtoken: data.login.token,
    sessionid: data.login.sessionid,
    lgdomain: ref
}, function(data) { … });


来源:https://stackoverflow.com/questions/21238407/media-wiki-second-post-still-returns-needtoken-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!