[Qt-qml] Authentication from a QML application
Juha Turunen
turunen at iki.fi
Tue Oct 18 19:43:31 CEST 2011
On Tue, Oct 18, 2011 at 6:13 PM, Johan Paul <johan.paul at gmail.com> wrote:
> HTTP Auth is your traditional browser popup to log in to sites with.
> AFAIK there is no way to do this in QML right now. But I would also like
> to be proven wrong (or hear it's available in QtQuick2).
QML's XHR implements the good old W3C API which has support for HTTP
authentication. Just pass the username and password as parameters in
the call to send().
import QtQuick 1.0
Item
{
width: 400
height: 400
MouseArea {
anchors.fill: parent
onClicked: {
var doc = new XMLHttpRequest();
doc.onreadystatechange = function() {
if (doc.readyState == XMLHttpRequest.HEADERS_RECEIVED) {
console.log("Headers:");
console.log(doc.getAllResponseHeaders());
} else if (doc.readyState == XMLHttpRequest.DONE) {
console.log("Response:");
console.log(doc.responseText);
}
}
doc.open("GET",
"http://koivi.com/php-http-auth/protect.php", true, "tester",
"testing");
doc.send();
}
}
}
More information about the Qt-qml
mailing list