0

I want to get a response from the server. I am making a rest api request using "Qt C++" framework. I am able to connect to the server but not able to get the response. The jazz server supports only xml format. I am a beginner in qt.

.pro

    QT += widgets
    TEMPLATE += app
    CONFIG += c++17 console
    CONFIG -= app_bundle

    # You can make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated                                 
    before Qt 6.0.0

    SOURCES += \
    main.cpp

    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target

    HEADERS += \
        main.h

main.h

    #ifndef MAIN_H
    #define MAIN_H
    #include <QtNetwork/QNetworkAccessManager>
    #include <QtNetwork/QNetworkReply>
    #include <QApplication>

    class MyObject : public QObject {
    Q_OBJECT
    public:
    explicit MyObject(QApplication* application);
    void TestConnection() const;
    static void ReplyFinished(QNetworkReply *reply);

    QNetworkAccessManager *manager;
    };
    #endif // MAIN_H

main.cpp

    #include <iostream>
    #include "main.h"

    MyObject::MyObject(QApplication* app) {
        manager = new QNetworkAccessManager(app);
    }

    void MyObject::TestConnection() const {
    auto status = connect(manager, &QNetworkAccessManager::finished,
                  this, &MyObject::ReplyFinished);
    qDebug() << "Connection status:" << status;

    manager->get(QNetworkRequest(QUrl("www.jazz.net")));
    }

    void MyObject::ReplyFinished(QNetworkReply *reply) {
        QString answer = reply->readAll();
        qDebug() << answer;
        QApplication::quit();
    }

    int main(int argc, char *argv[]) {
        auto *app = new QApplication(argc, argv);
        auto myObject = new MyObject(app);
        myObject->TestConnection();
        return QApplication::exec();
    }

The output is :

    Connection status: true
    
    qt.tlsbackend.ossl: Failed to load libssl/libcrypto.
    
    ""      //The response is empty

Note: I am looking for a specific request-response to the jazz server and the URL format is {format: https://:/}

dell rawal
  • 11
  • 5
  • `libcrypto` is an [OpenSSL](https://www.openssl.org) library. Thus you man need to locate/install/[build](https://wiki.openssl.org/index.php/Compilation_and_Installation) yourself the OpenSSL libraries. – absolute.madness Aug 17 '22 at 06:08
  • can you provide further details to build openssl – dell rawal Aug 17 '22 at 06:21
  • the build instructions depend on the OS you have, basically they boil down to commands like `. /config` and `make`: https://wiki.openssl.org/index.php/Compilation_and_Installation#Quick – absolute.madness Aug 17 '22 at 06:28
  • i have a window 10 – dell rawal Aug 17 '22 at 06:29
  • See [this](https://stackoverflow.com/questions/73312843/qml-error-ssl-sockets-are-not-supported-on-this-platform/73313689#73313689) post then. I presumed unix (incorrectly), because libssl/libcrypto is a unix way of naming the shared libraries. – absolute.madness Aug 17 '22 at 06:34
  • The main concern is i.e. the server only supports the xml format. After making a successful request. I am not able to retrieve the xml response(i.e. data). It gives a ""(NULL). Can anyone explain this part or have a solution? – dell rawal Aug 17 '22 at 10:51
  • what `reply->error`? Also, try not to convert the result of `readAll`, to `QSring`, save it to `QByteArray` first – absolute.madness Aug 17 '22 at 11:53
  • The output obtained is : URL connected reponse content httpFinished datafetch data "" //The response is not retrieved(in xml format) – dell rawal Aug 17 '22 at 14:22

0 Answers0