我的问题是我相信我已经正确构建了请求,但是我得到 [400 {"message":"Problems parsing 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});