QNetworkReply always getting error



  • Hello everybody,

    I'm using QNetwork since a bit time in my app to get information from webservices and i never got problem with it till today.
    Here is my doRequest function i use :

    QString                            Request::doRequest(const QString& request, RequestType type, const QByteArray& data)
    {
        _isProcessing = true;
        QObject::connect(&_networkManager, SIGNAL(finished(QNetworkReply*)), &_eventLoop, SLOT(quit()));
        QUrl url(request);
        QNetworkRequest req(url);
        switch (type)
        {
        case e_GET :
            _reply = _networkManager.get(req);
            break;
        case e_POST :
            _reply = _networkManager.post(req, data);
            break;
        case e_PUT :
            _reply = _networkManager.put(req, data);
            break;
        case e_DELETE :
            _reply = _networkManager.deleteResource(req);
            break;
        }
        _eventLoop.exec();
        if (_reply->error() == QNetworkReply::NoError)
            {
                QString result = _reply->readAll();
                std::cout << "RESULT = " << result.toStdString() << std::endl;
                delete _reply;
                _isProcessing = false;
                return (result);
            }
        else
        {
            std::cerr << "Error : \"" << _reply->errorString().toStdString() << "\"" << std::endl;
            exit(-1);
        }
        delete _reply;
        _isProcessing = false;
        return ("");
    }
    

    It works well except for one particular webservice where i get "Protocol "" is unknown", the webservice URL is good when i copy paste it in my browser it works. I can't understand why this error append.



  • Hi @MrDiv

    What is the URL you're pasting? (assuming its something you're able to share)

    Try adding a couple of qDebug's like:

        qDebug() << request;
        QUrl url(request);
        qDebug() << url;
        qDebug() << url.scheme();
    

    That might give some clues.



  • Thank you for your answer @Paul-Colby,

    I cant really share the URL here, but i trust you enough to share it to you in private if you think the problem is coming from there.
    I tried your debug, qDebug() << request; is printing the request, the rest is outputting nothing.



  • @MrDiv said:

    qDebug() << request; is printing the request, the rest is outputting nothing.

    It does sound like an issue with QUrl understanding the URL then. You could try breaking the URL down by pasting in just a the first few parts at a time to see when if it breaks at a particular point.

    I cant really share the URL here, but i trust you enough to share it to you in private if you think the problem is coming from there.

    Understood. I'm more than happy to take a look if you do send it privately. I certainly will not repeat / share the URL with anyone.

    Cheers.


Log in to reply
 

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