Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Problems with HTTP-Query
Forum Updated to NodeBB v4.3 + New Features

Problems with HTTP-Query

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
7 Posts 3 Posters 1.5k Views
  • 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.
  • K Offline
    K Offline
    kylecorver
    wrote on last edited by
    #1

    Hi guys,
    I'm having issues connecting to a webserver and sending a http-query. So far my code worked fine with websites that use the standard port. Additionally I now have to use a different port, now I'm having trouble to establish the connection. My Programcode looks like the following:

    QEventLoop oEventLoop;
    
        QNetworkAccessManager oMgr;
        QObject::connect(&oMgr, SIGNAL(finished(QNetworkReply*)), &oEventLoop, SLOT(quit()));
    
        QUrl oUrl(QUrl("http://dummyurl.com"));
        oUrl.setPort(1234);
        QNetworkRequest oRequest(oUrl);
        oRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
    
        QUrlQuery oPostData;
        QJsonDocument oJsonQuery(aParams);
        oPostData.addQueryItem("query", oJsonQuery.toJson(QJsonDocument::Compact));
    
        QNetworkReply* pReply = oMgr.post(oRequest, oPostData.toString().toUtf8());
        oEventLoop.exec();
    
        if(pReply->error()!=QNetworkReply::NoError) {
            qDebug()<<pReply->errorString();
        }
    

    At first I tried using QUrl oUrl(QUrl("http://dummyurl.com:1234"));, but this one wont' work, too.

    What am I doing wrong?

    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Can you access that URL and port via a web browser?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      K 1 Reply Last reply
      0
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        and what exactly isn't working?! What do you expect and what do you get?

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        K 1 Reply Last reply
        0
        • jsulmJ jsulm

          Can you access that URL and port via a web browser?

          K Offline
          K Offline
          kylecorver
          wrote on last edited by
          #4

          @jsulm Yeah URL and port are accessible via Webbrowser or php query, just the QT-Implementation can't establish a connection.

          1 Reply Last reply
          0
          • jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            What is the output of this line:

            qDebug()<<pReply->errorString();
            

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            K 1 Reply Last reply
            0
            • raven-worxR raven-worx

              and what exactly isn't working?! What do you expect and what do you get?

              K Offline
              K Offline
              kylecorver
              wrote on last edited by
              #6

              @raven-worx I would expect some text as answer from the server. I do not get anything. While debugging I found out, that my program can't even connect to the Url. I'm sorry I forgot the error message:
              "Connection timed out"
              So I guessed there is anything wrong with my Code, because the URL is reachable via Webbrowser or for example php.

              1 Reply Last reply
              0
              • jsulmJ jsulm

                What is the output of this line:

                qDebug()<<pReply->errorString();
                
                K Offline
                K Offline
                kylecorver
                wrote on last edited by
                #7

                @jsulm As I said already in another answer, I'm sorry that I forgot that message:
                "Connection timed out"

                1 Reply Last reply
                0

                • Login

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