QHttp über HTTPS ergibt ein "HTTP request failed"

Alles rund um die Programmierung mit Qt
Antworten
ms47
Beiträge: 35
Registriert: 22. Januar 2009 10:02

QHttp über HTTPS ergibt ein "HTTP request failed"

Beitrag von ms47 »

Hallo,

ich versuche mittels QHttp eine Verbindung zu einer Seite über https herzustellen. Leider bekomme ich den Fehler "HTTP request failed".
Das ist mal das Testprogramm.

Code: Alles auswählen

#include <QtCore/QCoreApplication>
#include <QBuffer>
#include <QHttp>
#include <QUrl>
#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QEventLoop loop;
    QBuffer buffer;
    QHttp http;

    QObject::connect(&http, SIGNAL(done(bool)), &loop, SLOT(quit()));

    QUrl url("https://gate1.goyyamobile.com/sms/sendsms.asp");
    url.addQueryItem("receiver", "testnummer");
    url.addQueryItem("sender", "tester");
    url.addQueryItem("msg", "hallo");
    url.addQueryItem("id", "id");
    url.addQueryItem("pw", "pw");
    url.addQueryItem("time", "0");
    url.addQueryItem("msgtype", "0");
    url.addQueryItem("test", "1");

    if( url.isValid()==false )
    {
        qDebug() << "Die eingebene Url ist falsch";
        return -1;
    }
    QString queryAndPath = url.encodedPath() + "?" + url.encodedQuery();
    qDebug() << url.host();
    qDebug() << queryAndPath;

    // http.setHost(url.host(), QHttp::ConnectionModeHttp ); // <---- das funktioniert
    http.setHost(url.host(), QHttp::ConnectionModeHttps, url.port(443) ); // <---- das funktioniert leider nicht
    http.get(queryAndPath, &buffer);

    loop.exec();
    qDebug() << "Fehler: " << http.errorString();

    QByteArray bytes;
    bytes = buffer.buffer();
    QString result(bytes);
    qDebug() << result;
    return 0;
}
Führe ich den Request per Http aus, also statt

Code: Alles auswählen

http.setHost(url.host(), QHttp::ConnectionModeHttps, url.port(443) );
dies:

Code: Alles auswählen

http.setHost(url.host(), QHttp::ConnectionModeHttp );
dann bekomme ich keinen Fehler und es funktioniert. Allerdings geht die Verbindung dann auch nicht über https.

Hat vielleicht jemand einen Tipp für mich? Danke schon mal.

Gruß
Markus

Noch zur Ergänzung:
Gebe ich diese Url im Firefox ein, dann geht es auch
https://gate1.goyyamobile.com/sms/sends ... e=0&test=1
Hat also nichts mir dem Server zu tun
Antworten