XmlHttpRequest error!



  • Here is my qml code.I want to open the remote server to get the json data for my app,but it returns "no" with an error like such thing:
    QString::arg: Argument missing: 无法解析SSLv2_client_method中的符号“SSLv2_client_method”:ssl, (/lib/libssl.so.1.0.0: undefined symbol: SSLv2_client_method)

    The code:
    import QtQuick 2.2

    Rectangle{
    width: 300;height:300

    function getData(){
        var xhr = new XMLHttpRequest();
        var op = xhr.open("GET","https://api.douban.com/v2/music/search?q=Secrets&count=1",true,"09e72702d8897e9b1db57508899c7bd1","b13ac8bf373bc51b");
        xhr.send();
        if(op){
            console.log("yes");
        } else{
            console.log("no");
        }
    }
    MouseArea{
        anchors.fill: parent
        onClicked: parent.getData()
         }  
     }


  • Alright!I have abandoned XmlHttpRequest method.I'm going to use XmlListModel.



  • If you still want what was the problem, I think that it was ssl. You are requesting an https address so Qt call SSL but it appear that SSL is not fully or correctly installed.
    Try to use http instead or to fix ssl :)



  • @MartinH Yeah! I still have to use XmlHttpRequest.And according to your reply, I changed the url to "http://mp3.baidu.com/dev/api/?tn=getinfo&ct=0&word=apologize&ie=utf-8&format=json".But it still returns "no",which means it doesn't work.What should I do now?

    The changed code is :
    function getData(){
    var xhr = new XMLHttpRequest();
    var op = xhr.open("GET","http://mp3.baidu.com/dev/api/?tn=getinfo&ct=0&word=apologize&ie=utf-8&format=json");
    xhr.send();
    if(op){
    console.log("yes");
    } else{
    console.log("no");
    }
    }


  • Moderators

    @DidaHarp XMLHttpRequest in QML only supports asynchronous only. So you may need to wait for the data to arrive. This can be done via state changes as usually done in JS

    function getData() {
        var xmlhttp = new XMLHttpRequest();
        var url = "http://mp3.baidu.com/dev/api/?tn=getinfo&ct=0&word=apologize&ie=utf-8&format=json";
    
        xmlhttp.onreadystatechange=function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                console.log(xmlhttp.responseText) // here is the output
            }
        }
        xmlhttp.open("GET", url);
        xmlhttp.send();
    }
    


  • @p3c0
    Wow!
    It worked!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.