#include "HttpRequestUtil.h"

HttpRequestUtil::HttpRequestUtil(QObject *parent) : QObject(parent)
{
    manager = new QNetworkAccessManager(this);
}


QNetworkReply * HttpRequestUtil::sendGetRequest(QNetworkRequest request)
{
    //发送请求
    QNetworkReply * reply = manager->get(request);

    // 同步等待
    QEventLoop eventLoop;
    connect(manager, &QNetworkAccessManager::finished, &eventLoop, &QEventLoop::quit);
    eventLoop.exec();

    return reply;
}

QNetworkReply * HttpRequestUtil::sendPostRequest(QNetworkRequest request, QByteArray params)
{
    //发送请求
    QNetworkReply * reply = manager->post(request, params);

    // 同步等待
    QEventLoop eventLoop;
    connect(manager, &QNetworkAccessManager::finished, &eventLoop, &QEventLoop::quit);
    eventLoop.exec();

    return reply;
}
