Titanium.Network.createHTTPClient() authenticate error
Hello.
I try to use this code:
<?xml version="1.0" encoding="utf-8"?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
</head>
<body>
<script type="text/javascript">
function click_action(){
var un = document.getElementById('username').value;
var pw = document.getElementById('password').value;
try {
var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function() {
//do work on "this.responseXML"
alert(this);
};
xhr.open("GET","http://"+un+":"+
pw+"@twitter.com/account/verify_credentials.xml");
xhr.send();
}
catch(err) {
Titanium.UI.createAlertDialog({
title: "Error",
message: String(err),
buttonNames: ['OK']
}).show();
}
}
</script>
<input type="text" id="username"/><br/>
<input type="password" id="password"/><br/>
<input type="button" onclick="click_action()" value="click me!"/>
</body>
</html>
But it returnes error on authenticate. Please, help me, what is it mistake in this code?
2 Answers
-
Hrm. You may be running into this bug https://appcelerator.lighthouseapp.com/projects/25719/tickets/335-titaniumnetworkhttpclient-does-not-fire-onload
Can you try adding this line before you send the request and see if it helps:
client.onreadystatechange = function() {}; -
Might not be related, but you should really use the twitter 'https' of that credentials url (despite the fact that their docs only use 'http')