1
0
mirror of https://gitee.com/drabel/LibQQt.git synced 2025-01-04 10:18:44 +08:00

update qqtwebaccessmanager

This commit is contained in:
tianduanrui 2018-02-26 10:15:13 +08:00
parent 7db0ca6c14
commit 4bf81ea982
5 changed files with 84 additions and 34 deletions

View File

@ -23,8 +23,7 @@ SUBDIRS = src/qqt.pro
#SUBDIRS += examples/tabwidgetexamples
#SUBDIRS += examples/qrcodeexample
#SUBDIRS += examples/qqtnetworkexample
#
SUBDIRS += test/voicetest
#SUBDIRS += test/voicetest
mac:lessThan(QT_MAJOR_VERSION , 5):SUBDIRS -= test/voicetest
#udp 嵌入式linuxQt编译了udp支持默认是支持的
#SUBDIRS += examples/qqtudpexample

5
licence.md Normal file
View File

@ -0,0 +1,5 @@
# LibQQt库使用协议
[返回](.)

1
src/frame/QQtApplication Normal file
View File

@ -0,0 +1 @@
#include <qqtapplication.h>

View File

@ -1,4 +1,4 @@
#include "qqtwebaccessmanager.h"
#include "qqtwebaccessmanager.h"
#include "qqtcore.h"
@ -31,20 +31,8 @@ void QQtWebAccessManager::sendGetRequest ( QQtWebAccessSession* session )
connect ( timer, SIGNAL ( timeout() ),
this, SLOT ( localReplyTimeOut() ) ); //超时信号
QNetworkRequest netRequest;
netRequest.setHeader ( QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded" );
netRequest.setUrl ( QUrl ( session->getWebAccessUrl() ) ); //地址信息
if ( session->getWebAccessUrl().toLower().startsWith ( "https" ) ) //https请求需ssl支持(下载openssl拷贝libeay32.dll和ssleay32.dll文件至Qt bin目录或程序运行目录)
{
QSslConfiguration sslConfig;
sslConfig.setPeerVerifyMode ( QSslSocket::VerifyNone );
sslConfig.setProtocol ( QSsl::TlsV1_1 );
netRequest.setSslConfiguration ( sslConfig );
}
QNetworkReply* reply = NULL;
reply = get ( netRequest );
QNetworkRequest& netRequest = session->webAccessRequest();
QNetworkReply* reply = get ( netRequest );
session->setWebAccessReply ( reply ); //发起get请求
/*下面关联信号和槽*/
@ -67,24 +55,61 @@ void QQtWebAccessManager::sendGetRequest ( QQtWebAccessSession* session )
QQtWebAccessSession* QQtWebAccessManager::sendGetRequest ( QString strUrl )
{
QQtWebAccessSession* session = manager->newWebAccessSession();
session->setWebAccessUrl ( strUrl );
sendGetRequest ( session );
QNetworkRequest netRequest;
netRequest.setHeader ( QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded" );
netRequest.setUrl ( QUrl ( strUrl ) ); //地址信息
if ( strUrl.toLower().startsWith ( "https" ) ) //https请求需ssl支持(下载openssl拷贝libeay32.dll和ssleay32.dll文件至Qt bin目录或程序运行目录)
{
QSslConfiguration sslConfig;
sslConfig.setPeerVerifyMode ( QSslSocket::VerifyNone );
sslConfig.setProtocol ( QSsl::TlsV1_1 );
netRequest.setSslConfiguration ( sslConfig );
}
QQtWebAccessSession* session = sendGetRequest ( netRequest );
return session;
}
QQtWebAccessSession* QQtWebAccessManager::sendGetRequests ( QStringList& strUrl )
QList<QQtWebAccessSession*> QQtWebAccessManager::sendGetRequests ( QStringList& strUrl )
{
QStringListIterator itor ( strUrl );
QList<QQtWebAccessSession*> sessionList;
while ( itor.hasNext() )
{
QString url = itor.next();
QQtWebAccessSession* session = sendGetRequest ( url );
sessionList.push_back ( session );
}
//当即使用有效,后续使用无效。
return sessionList;
}
QQtWebAccessSession* QQtWebAccessManager::sendGetRequest ( QNetworkRequest& netRequest )
{
QQtWebAccessSession* session = manager->newWebAccessSession();
session->webAccessRequest() = netRequest;
sendGetRequest ( session );
return session;
}
QQtWebAccessSession* QQtWebAccessManager::sendGetRequests ( QList<QNetworkRequest*>& netRequests )
QList<QQtWebAccessSession*> QQtWebAccessManager::sendGetRequests ( QList<QNetworkRequest>& netRequests )
{
QListIterator<QNetworkRequest> itor ( netRequests );
QList<QQtWebAccessSession*> sessionList;
while ( itor.hasNext() )
{
QNetworkRequest req = itor.next();
QQtWebAccessSession* session = sendGetRequest ( req );
sessionList.push_back ( session );
}
//当即使用有效,后续使用无效。
return sessionList;
}
QQtWebAccessSession* QQtWebAccessManager::sendPostRequest ( QString strUrl )
@ -115,7 +140,7 @@ void QQtWebAccessManager::finished ( QNetworkReply* reply )
void QQtWebAccessManager::authenticationRequired ( QNetworkReply* r, QAuthenticator* a )
{
//pline() << r << a;
pline() << r << a;
}
void QQtWebAccessManager::proxyAuthenticationRequired ( QNetworkProxy p, QAuthenticator* a )

View File

@ -1,15 +1,23 @@
#ifndef QQTWEBWORKCLIENT_H
#ifndef QQTWEBWORKCLIENT_H
#define QQTWEBWORKCLIENT_H
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
//import this struct will not build fail
#include <QNetworkProxy>
#include <QSslError>
#include <QStringList>
#include <QUuid>
#include <QNetworkCookie>
#include <QNetworkCookieJar>
#include <qqt-qt.h>
#include <qqt-local.h>
#include <qqtcore.h>
#include <QUuid>
class QQTSHARED_EXPORT QQtWebAccessSession : public QObject
{
@ -23,24 +31,34 @@ public:
}
virtual ~QQtWebAccessSession() {}
//timer
void setTimeOut ( int timeout ) {
m_pTimer->setInterval ( timeout );
}
QTimer* getTimer() {
return m_pTimer;
}
//request
QString getWebAccessUrl() {
return mNetworkRequest.url().toString();
}
void setWebAccessUrl ( QString strUrl ) {
mNetworkRequest.setUrl ( QUrl ( m_strUrl ) );
}
QNetworkRequest& webAccessRequest() {
return mNetworkRequest;
}
//reply
QNetworkReply* getWebAccessReply() {
return m_pNetworkReply;
}
void setWebAccessReply ( QNetworkReply* reply ) {
m_pNetworkReply = reply;
}
QString getWebAccessUrl() {
return m_strUrl;
}
void setWebAccessUrl ( QString strUrl ) {
m_strUrl = strUrl;
}
//session name
QString getWebAccessSessionName() {
return m_strSessionName;
}
@ -49,6 +67,8 @@ public:
}
private:
//request
QNetworkRequest mNetworkRequest;
//call back
QNetworkReply* m_pNetworkReply;
//call time out
@ -154,9 +174,9 @@ public:
void sendGetRequest ( QQtWebAccessSession* session );
QQtWebAccessSession* sendGetRequest ( QString strUrl );
QQtWebAccessSession* sendGetRequests ( QStringList& strUrls );
QList<QQtWebAccessSession*> sendGetRequests ( QStringList& strUrls );
QQtWebAccessSession* sendGetRequest ( QNetworkRequest& netRequest );
QQtWebAccessSession* sendGetRequests ( QList<QNetworkRequest*>& netRequests );
QList<QQtWebAccessSession*> sendGetRequests ( QList<QNetworkRequest>& netRequests );
QQtWebAccessSession* sendPostRequest ( QString strUrl );