Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Make an XMLHttpRequest on Android



  • Hi all,
    I'm trying to perform an XMLHttpRequest in QML over plain HTTP inside my LAN. It works well on my computer, but it fails once deployed on an Android device with status 0.
    My goal was to build my app using CMake but I couldn't make the AndroidManifest.xml working so I'm trying this from a QMake-built app (where the android manifest is working). So I added android.permission.INTERNET but the request still ends up with status 0.

    My test qmake app is very simple, I created it as an empty QtQuick template from QtCreator and this is my main.qml.

    import QtQuick 2.12
    import QtQuick.Window 2.12
    
    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
        Component.onCompleted: updateModel()
        function updateModel() {
            var doc = new XMLHttpRequest();
            doc.onreadystatechange = function() {
                if (doc.readyState === XMLHttpRequest.DONE) {
                    console.log("status req: "+doc.status)
                    if (doc.status === 200) {
                        console.log(doc.responseText)
                    }
                }
            }
            doc.open("GET", "192.168.1.14:6789/AuroraClimb/list");
            doc.send();
        }
    }
    

    I am using Qt5.12.10.
    What am I doing wrong in this http call? Why it does return with status 0?
    If I need to give you some other details, please tell me.
    Thank you!


Log in to reply