Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QNetworkReply always getting error
Forum Updated to NodeBB v4.3 + New Features

QNetworkReply always getting error

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 882 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MrDivM Offline
    MrDivM Offline
    MrDiv
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      1
      • MrDivM Offline
        MrDivM Offline
        MrDiv
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • Paul ColbyP Offline
          Paul ColbyP Offline
          Paul Colby
          wrote on last edited by
          #4

          @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.

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved