Problems with HTTP-Query



  • 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?


  • Moderators

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


  • Moderators

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



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


  • Moderators

    What is the output of this line:

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


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



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


Log in to reply
 

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