Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Problems with HTTP-Query

    Mobile and Embedded
    3
    7
    963
    Loading More Posts
    • 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
      kylecorver last edited by

      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 Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • raven-worx
          raven-worx Moderators last edited by

          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 Reply Quote 0
          • K
            kylecorver @jsulm last edited by

            @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 Reply Quote 0
            • jsulm
              jsulm Lifetime Qt Champion last edited by

              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 Reply Quote 0
              • K
                kylecorver @raven-worx last edited by

                @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 Reply Quote 0
                • K
                  kylecorver @jsulm last edited by

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

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post