|
|
@@ -34,7 +34,12 @@ bool HttpClient::getRequest(const QString &url, const QString &token, const QByt
|
|
|
requestInfo.setUrl(QUrl(strUrl));
|
|
|
requestInfo.setRawHeader("Authorization", token.toUtf8());
|
|
|
requestInfo.setRawHeader("tenant_id", Config()->tenant_id.toUtf8());
|
|
|
- // 发送 post 请求
|
|
|
+
|
|
|
+ qDebug().noquote() << "[HTTP GET] url=" << strUrl
|
|
|
+ << " tenant_id=" << Config()->tenant_id
|
|
|
+ << " Authorization=" << (token.isEmpty() ? "(empty)" : "(set)");
|
|
|
+
|
|
|
+ // 发送 get 请求
|
|
|
QNetworkReply* reply = pHttpMgr->get(requestInfo);
|
|
|
|
|
|
// 添加超时处理,1ms 超时
|
|
|
@@ -94,6 +99,11 @@ bool HttpClient::postRequest(const QString &url, const QString &token, const QBy
|
|
|
requestInfo.setRawHeader("Authorization", token.toUtf8());
|
|
|
requestInfo.setRawHeader("tenant_id", Config()->tenant_id.toUtf8());
|
|
|
|
|
|
+ qDebug().noquote() << "[HTTP POST] url=" << strUrl
|
|
|
+ << " tenant_id=" << Config()->tenant_id
|
|
|
+ << " Authorization=" << (token.isEmpty() ? "(empty)" : "(set)")
|
|
|
+ << " body=" << QString::fromUtf8(inData);
|
|
|
+
|
|
|
// 发送 post 请求
|
|
|
QNetworkReply* reply = pHttpMgr->post(requestInfo, inData);
|
|
|
|
|
|
@@ -151,7 +161,12 @@ bool HttpClient::putRequest(const QString &url, const QString &token, const QByt
|
|
|
requestInfo.setRawHeader("Authorization", token.toUtf8());
|
|
|
requestInfo.setRawHeader("tenant_id", Config()->tenant_id.toUtf8());
|
|
|
|
|
|
- // 发送 post 请求
|
|
|
+ qDebug().noquote() << "[HTTP PUT] url=" << strUrl
|
|
|
+ << " tenant_id=" << Config()->tenant_id
|
|
|
+ << " Authorization=" << (token.isEmpty() ? "(empty)" : "(set)")
|
|
|
+ << " body=" << QString::fromUtf8(inData);
|
|
|
+
|
|
|
+ // 发送 put 请求
|
|
|
QNetworkReply* reply = pHttpMgr->put(requestInfo, inData);
|
|
|
|
|
|
// 添加超时处理,1ms 超时
|
|
|
@@ -198,6 +213,7 @@ void HttpClient::run()
|
|
|
{
|
|
|
if(m_workStat != httpWorkStat::httpWorkSleep)
|
|
|
{
|
|
|
+ m_mutex.lock();
|
|
|
QString res = "";
|
|
|
switch(m_workStat)
|
|
|
{
|
|
|
@@ -208,9 +224,29 @@ void HttpClient::run()
|
|
|
}
|
|
|
|
|
|
QByteArray bb = res.toUtf8();
|
|
|
- m_mutex.unlock();
|
|
|
+ QString postUrl = m_postUrl;
|
|
|
m_workStat = httpWorkStat::httpWorkSleep;
|
|
|
- //emit signalResponseData(m_id, m_postUrl, bb);
|
|
|
+ m_mutex.unlock();
|
|
|
+
|
|
|
+ // GET 请求在工作线程完成,在此发射信号,避免在主线程阻塞
|
|
|
+ if (postUrl == Config()->jobTicketsUrl) {
|
|
|
+ emit signalResponseGetJobTickets(bb);
|
|
|
+ }
|
|
|
+ else if (postUrl == Config()->workNodeDetail) {
|
|
|
+ emit signalResponseGetWorkNodeDetail(bb);
|
|
|
+ }
|
|
|
+ else if (postUrl == Config()->workNodeDetailForm) {
|
|
|
+ emit signalResponseGetFormById(bb);
|
|
|
+ }
|
|
|
+ else if (postUrl == Config()->userInfoUrl) {
|
|
|
+ emit signalResponseGetUserInfoUrl(bb);
|
|
|
+ }
|
|
|
+ else if (postUrl == Config()->keyMACByNFC) {
|
|
|
+ emit signalResponseGetKeyMAC(bb);
|
|
|
+ }
|
|
|
+ else if (postUrl == Config()->isolationPointById) {
|
|
|
+ emit signalResponseGetIsolationPointInfo(bb);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
msleep(10);
|
|
|
@@ -238,7 +274,11 @@ QString HttpClient::postJsonRequest()
|
|
|
requestInfo.setRawHeader("Authorization", auth.toUtf8());
|
|
|
requestInfo.setRawHeader("tenant-id", Config()->tenant_id.toUtf8());
|
|
|
|
|
|
- // QString strInfo = requestInfo.url().toString();
|
|
|
+ qDebug().noquote() << "[HTTP POST(Json)] url=" << url
|
|
|
+ << " tenant_id=" << Config()->tenant_id
|
|
|
+ << " postUrl=" << m_postUrl
|
|
|
+ << " Authorization=" << (auth.isEmpty() ? "(empty)" : "(set)")
|
|
|
+ << " body=" << QString::fromUtf8(m_httpData);
|
|
|
|
|
|
// 发送 post 请求
|
|
|
QNetworkReply* reply = pHttpMgr->post(requestInfo, m_httpData);
|
|
|
@@ -337,6 +377,11 @@ QString HttpClient::postFormdataRequest()
|
|
|
requestInfo.setRawHeader("Authorization", auth.toUtf8());
|
|
|
requestInfo.setRawHeader("tenant_id", Config()->tenant_id.toUtf8());
|
|
|
|
|
|
+ qDebug().noquote() << "[HTTP POST(FormData)] url=" << url
|
|
|
+ << " tenant_id=" << Config()->tenant_id
|
|
|
+ << " postUrl=" << m_postUrl
|
|
|
+ << " Authorization=" << (auth.isEmpty() ? "(empty)" : "(set)");
|
|
|
+
|
|
|
// 发送 post 请求
|
|
|
QNetworkReply* reply = pHttpMgr->post(requestInfo, multiPart);
|
|
|
multiPart->setParent(reply); // reply删除时会自动删除multiPart
|
|
|
@@ -420,6 +465,13 @@ QString HttpClient::getRequest()
|
|
|
QString auth = m_token;
|
|
|
requestInfo.setRawHeader("Authorization", auth.toUtf8());
|
|
|
requestInfo.setRawHeader("tenant_id", Config()->tenant_id.toUtf8());
|
|
|
+
|
|
|
+ qDebug().noquote() << "[HTTP GET(thread)] url=" << url
|
|
|
+ << " tenant_id=" << Config()->tenant_id
|
|
|
+ << " postUrl=" << m_postUrl
|
|
|
+ << " query=" << getJsonStr
|
|
|
+ << " Authorization=" << (auth.isEmpty() ? "(empty)" : "(set)");
|
|
|
+
|
|
|
// 发送 get 请求
|
|
|
QNetworkReply* reply = pHttpMgr->get(requestInfo);
|
|
|
|
|
|
@@ -483,6 +535,12 @@ QString HttpClient::putJsonRequest()
|
|
|
requestInfo.setRawHeader("Authorization", auth.toUtf8());
|
|
|
requestInfo.setRawHeader("tenant-id", Config()->tenant_id.toUtf8());
|
|
|
|
|
|
+ qDebug().noquote() << "[HTTP PUT(Json)] url=" << url
|
|
|
+ << " tenant_id=" << Config()->tenant_id
|
|
|
+ << " postUrl=" << m_postUrl
|
|
|
+ << " Authorization=" << (auth.isEmpty() ? "(empty)" : "(set)")
|
|
|
+ << " body=" << QString::fromUtf8(m_httpData);
|
|
|
+
|
|
|
// 发送 put 请求
|
|
|
QNetworkReply* reply = pHttpMgr->put(requestInfo, m_httpData);
|
|
|
|
|
|
@@ -590,35 +648,16 @@ void HttpClient::slotPostRequestData(quint64 id, QString postUrl, QByteArray dat
|
|
|
|
|
|
void HttpClient::slotGetRequestData(quint64 id, QString postUrl, QByteArray data, QString token)
|
|
|
{
|
|
|
+ // 不在主线程执行同步 getRequest(),否则会阻塞 UI 导致“无响应”
|
|
|
+ // 将参数交给工作线程,由 run() 中执行 getRequest() 并发射信号
|
|
|
m_mutex.lock();
|
|
|
this->m_id = id;
|
|
|
this->m_postUrl = postUrl;
|
|
|
this->m_httpData = data;
|
|
|
this->m_token = token;
|
|
|
HttpClient::sToken = token;
|
|
|
-
|
|
|
- QString res = getRequest();
|
|
|
- QByteArray bb = res.toUtf8();
|
|
|
+ this->m_workStat = httpWorkStat::httpWorkGet;
|
|
|
m_mutex.unlock();
|
|
|
-
|
|
|
- if (m_postUrl == Config()->jobTicketsUrl) {
|
|
|
- emit signalResponseGetJobTickets(bb);
|
|
|
- }
|
|
|
- else if (m_postUrl == Config()->workNodeDetail) {
|
|
|
- emit signalResponseGetWorkNodeDetail(bb);
|
|
|
- }
|
|
|
- else if (m_postUrl == Config()->workNodeDetailForm) {
|
|
|
- emit signalResponseGetFormById(bb);
|
|
|
- }
|
|
|
- else if (m_postUrl == Config()->userInfoUrl) {
|
|
|
- emit signalResponseGetUserInfoUrl(bb);
|
|
|
- }
|
|
|
- else if (m_postUrl == Config()->keyMACByNFC) {
|
|
|
- emit signalResponseGetKeyMAC(bb);
|
|
|
- }
|
|
|
- else if (m_postUrl == Config()->isolationPointById) {
|
|
|
- emit signalResponseGetIsolationPointInfo(bb);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
void HttpClient::slotPutRequestData(quint64 id, QString postUrl, QByteArray data, QByteArray file, QString token)
|