实现了登录、注册、上传下载等功能。
//代码核心
//设置url
QUrl url("········");
//设置url的query参数
QUrlQuery query;
query.addQueryItem("fileName", "·······");
query.addQueryItem("owner", mUsername);
query.addQueryItem("repository", mRepoName);
url.setQuery(query.query());
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json;charset=UTF-8");
//设置token值,带到头里面
if (!mToken.isEmpty())
{
request.setRawHeader("token", mToken.toLatin1());
}
auto netnam = std::make_shared<QNetworkAccessManager>();
mpReply = netnam->get(request);
QEventLoop eventLoop;
QObject::connect(netnam.get(), &QNetworkAccessManager::finished, &eventLoop, &QEventLoop::quit);
eventLoop.exec();
//TODO:没有返回信息?
QByteArray bytes = mpReply->readAll();
QString bs = QString(bytes);
//上传功能示例
//使用按钮响应<