使用javascript(Appcelerator)进行github基本身份验证

时间:2012-06-26 03:31:17

标签: javascript appcelerator github-api

我的问题是我相信我已正确构建了请求,但我收到了[400 {“message”:“解析JSON的问题”}}

这是我的代码:

var xhr = Ti.Network.createHTTPClient({
        onload : function() {
             Ti.API.debug(this.responseText);

            json = JSON.parse(this.responseText);

            callback(json);
        },
        onerror : function(e) {
            alert('error!');
            Ti.API.info(e.error + " " + this.status + " " + this.responseText);
        }
    });

    xhr.validatesSecureCertificate = true;
    xhr.open("POST", "https://api.github.com/authorizations");
    xhr.setTimeout(10000);
    authstr = 'Basic ' + Titanium.Utils.base64encode(User.username + ':' + User.password);
    xhr.setRequestHeader('Authorization', authstr);
    xhr.send({username: User.username, password: User.password});

1 个答案:

答案 0 :(得分:1)

我只是错过了JSON.stringify方法......在我身上:P。谢谢!