本文整理汇总了C++中QNetworkProxy::setType方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkProxy::setType方法的具体用法?C++ QNetworkProxy::setType怎么用?C++ QNetworkProxy::setType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QNetworkProxy
的用法示例。
在下文中一共展示了QNetworkProxy::setType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetProxy
void NetworkAccessManager::SetProxy(const QString& server, int Port, bool IsHttp, const QString& name, const QString& password, const QString& callback)
{
if(server.isEmpty() || Port<=0)
{
CaptureManager->setProxy(QNetworkProxy::NoProxy);
}else
{
QNetworkProxy proxy;
if(IsHttp)
{
proxy.setType(QNetworkProxy::HttpProxy);
}else
{
proxy.setType(QNetworkProxy::Socks5Proxy);
}
proxy.setHostName(server);
proxy.setPort(Port);
proxy.setUser(name);
proxy.setPassword(password);
CaptureManager->setProxy(proxy);
}
Worker->SetScript(callback);
Worker->RunSubScript();
}
示例2: loadSettings
void ThreadHandler::loadSettings() {
settings->beginGroup("options");
autoClose = settings->value("automatic_close", false).toBool();
maxDownloads = settings->value("concurrent_downloads", 1).toInt();
settings->endGroup();
settings->beginGroup("network");
QNetworkProxy proxy;
if (settings->value("use_proxy", false).toBool()) {
proxy.setType((QNetworkProxy::ProxyType)(settings->value("proxy_type", QNetworkProxy::HttpProxy).toInt()));
proxy.setHostName(settings->value("proxy_hostname", "").toString());
proxy.setPort(settings->value("proxy_port", 0).toUInt());
if (settings->value("proxy_auth", false).toBool()) {
proxy.setUser(settings->value("proxy_user", "").toString());
proxy.setPassword(settings->value("proxy_pass", "").toString());
}
}
else {
proxy.setType(QNetworkProxy::NoProxy);
}
QNetworkProxy::setApplicationProxy(proxy);
settings->endGroup();
}
示例3: loadSettings
void NetworkAccessManager::loadSettings()
{
QSettings settings;
settings.beginGroup(QLatin1String("proxy"));
QNetworkProxy proxy;
if (settings.value(QLatin1String("enabled"), false).toBool()) {
if (settings.value(QLatin1String("type"), 0).toInt() == 0)
proxy.setType(QNetworkProxy::Socks5Proxy);
else
proxy.setType(QNetworkProxy::HttpProxy);
proxy.setHostName(settings.value(QLatin1String("hostName")).toString());
proxy.setPort(settings.value(QLatin1String("port"), 1080).toInt());
proxy.setUser(settings.value(QLatin1String("userName")).toString());
proxy.setPassword(settings.value(QLatin1String("password")).toString());
}
setProxy(proxy);
settings.endGroup();
#ifndef QT_NO_OPENSSL
QSslConfiguration sslCfg = QSslConfiguration::defaultConfiguration();
QList<QSslCertificate> ca_list = sslCfg.caCertificates();
QList<QSslCertificate> ca_new = QSslCertificate::fromData(settings.value(QLatin1String("CaCertificates")).toByteArray());
ca_list += ca_new;
sslCfg.setCaCertificates(ca_list);
QSslConfiguration::setDefaultConfiguration(sslCfg);
#endif
}
示例4: SetProxy
static QNetworkProxy SetProxy(int type, QString host, unsigned int port, QString name, QString pass)
{
QNetworkProxy proxy;
switch (type)
{
case 0:
QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy);
return proxy;
case 1:
proxy.setType(QNetworkProxy::Socks5Proxy);
break;
case 2:
proxy.setType(QNetworkProxy::HttpProxy);
break;
case 3:
proxy.setType(QNetworkProxy::HttpCachingProxy);
break;
case 4:
proxy.setType(QNetworkProxy::FtpCachingProxy);
break;
default:
return proxy;
}
proxy.setHostName(host);
proxy.setPort(port);
proxy.setUser(name);
proxy.setPassword(pass);
QNetworkProxy::setApplicationProxy(proxy);
return proxy;
}
示例5: checkProxy
void PBSystemTab::checkProxy()
{
bool ok;
int port;
// If no proxy set
if ( pcbsd::Utils::getProxyURL().isEmpty() )
return;
QNetworkProxy proxy;
if ( pcbsd::Utils::getProxyType() == "SOCKS5" )
proxy.setType(QNetworkProxy::Socks5Proxy);
else
proxy.setType(QNetworkProxy::HttpProxy);
proxy.setHostName(pcbsd::Utils::getProxyURL());
port = pcbsd::Utils::getProxyPort().toInt(&ok);
if ( ! pcbsd::Utils::getProxyPort().isEmpty() && ok )
proxy.setPort(port);
if ( ! pcbsd::Utils::getProxyUser().isEmpty() )
proxy.setUser(pcbsd::Utils::getProxyUser());
if ( ! pcbsd::Utils::getProxyPass().isEmpty() )
proxy.setPassword(pcbsd::Utils::getProxyPass());
QNetworkProxy::setApplicationProxy(proxy);
}
示例6: setupQtProxyFromConfig
void ClientProxy::setupQtProxyFromConfig()
{
Mirall::MirallConfigFile cfg;
int proxyType = QNetworkProxy::DefaultProxy;
QNetworkProxy proxy;
// if there is no config file, default to system proxy.
if( cfg.exists() ) {
proxyType = cfg.proxyType();
proxy = proxyFromConfig(cfg);
}
switch(proxyType) {
case QNetworkProxy::NoProxy:
QNetworkProxyFactory::setUseSystemConfiguration(false);
QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy);
break;
case QNetworkProxy::DefaultProxy:
QNetworkProxyFactory::setUseSystemConfiguration(true);
break;
case QNetworkProxy::Socks5Proxy:
proxy.setType(QNetworkProxy::Socks5Proxy);
QNetworkProxyFactory::setUseSystemConfiguration(false);
QNetworkProxy::setApplicationProxy(proxy);
break;
case QNetworkProxy::HttpProxy:
proxy.setType(QNetworkProxy::HttpProxy);
QNetworkProxyFactory::setUseSystemConfiguration(false);
QNetworkProxy::setApplicationProxy(proxy);
break;
default:
break;
}
}
示例7: getProxySettings
bool OptionsModel::getProxySettings(QNetworkProxy& proxy) const
{
// Directly query current base proxy, because
// GUI settings can be overridden with -proxy.
proxyType curProxy;
if (GetProxy(NET_IPV4, curProxy)) {
if (curProxy.second == 5) {
proxy.setType(QNetworkProxy::Socks5Proxy);
proxy.setHostName(QString::fromStdString(curProxy.first.ToStringIP()));
proxy.setPort(curProxy.first.GetPort());
return true;
}
else
return false;
}
else
proxy.setType(QNetworkProxy::NoProxy);
return true;
}
示例8: setProperty
void HTTPTransport::setProperty( const QString& aProperty, const QString& aValue )
{
FUNCTION_CALL_TRACE;
if( aProperty == HTTPNUMBEROFRESENDATTEMPTSPROP )
{
LOG_DEBUG( "Setting property" << aProperty <<":" << aValue );
iMaxNumberOfResendAttempts = aValue.toInt();
}
else if( aProperty == HTTPPROXYHOSTPROP )
{
LOG_DEBUG( "Setting property" << aProperty <<":" << aValue );
QNetworkProxy proxy = iManager->proxy();
proxy.setType( QNetworkProxy::HttpProxy );
proxy.setHostName(aValue);
iManager->setProxy(proxy);
}
else if( aProperty == HTTPPROXYPORTPROP )
{
LOG_DEBUG( "Setting property" << aProperty <<":" << aValue );
QNetworkProxy proxy = iManager->proxy();
proxy.setType( QNetworkProxy::HttpProxy );
proxy.setPort( aValue.toInt() );
iManager->setProxy(proxy);
}
}
示例9: syncSettings
void QtMarbleConfigDialog::syncSettings()
{
d->m_settings.sync();
QNetworkProxy proxy;
// Make sure that no proxy is used for an empty string or the default value:
if ( proxyUrl().isEmpty() || proxyUrl() == "http://" ) {
proxy.setType( QNetworkProxy::NoProxy );
} else {
if ( proxyType() == Marble::Socks5Proxy ) {
proxy.setType( QNetworkProxy::Socks5Proxy );
}
else if ( proxyType() == Marble::HttpProxy ) {
proxy.setType( QNetworkProxy::HttpProxy );
}
else {
mDebug() << "Unknown proxy type! Using Http Proxy instead.";
proxy.setType( QNetworkProxy::HttpProxy );
}
}
proxy.setHostName( proxyUrl() );
proxy.setPort( proxyPort() );
if ( proxyAuth() ) {
proxy.setUser( proxyUser() );
proxy.setPassword( proxyPass() );
}
QNetworkProxy::setApplicationProxy(proxy);
}
示例10: applyProxySettings
void DownloadThread::applyProxySettings() {
QNetworkProxy proxy;
const Preferences pref;
if (pref.isProxyEnabled()) {
// Proxy enabled
proxy.setHostName(pref.getProxyIp());
proxy.setPort(pref.getProxyPort());
// Default proxy type is HTTP, we must change if it is SOCKS5
const int proxy_type = pref.getProxyType();
if (proxy_type == Proxy::SOCKS5 || proxy_type == Proxy::SOCKS5_PW) {
qDebug() << Q_FUNC_INFO << "using SOCKS proxy";
proxy.setType(QNetworkProxy::Socks5Proxy);
} else {
qDebug() << Q_FUNC_INFO << "using HTTP proxy";
proxy.setType(QNetworkProxy::HttpProxy);
}
// Authentication?
if (pref.isProxyAuthEnabled()) {
qDebug("Proxy requires authentication, authenticating");
proxy.setUser(pref.getProxyUsername());
proxy.setPassword(pref.getProxyPassword());
}
} else {
proxy.setType(QNetworkProxy::NoProxy);
}
m_networkManager.setProxy(proxy);
}
示例11: qDebug
void Net::DownloadManager::applyProxySettings()
{
const auto *proxyManager = ProxyConfigurationManager::instance();
const ProxyConfiguration proxyConfig = proxyManager->proxyConfiguration();
QNetworkProxy proxy;
if (!proxyManager->isProxyOnlyForTorrents() && (proxyConfig.type != ProxyType::None)) {
// Proxy enabled
proxy.setHostName(proxyConfig.ip);
proxy.setPort(proxyConfig.port);
// Default proxy type is HTTP, we must change if it is SOCKS5
if ((proxyConfig.type == ProxyType::SOCKS5) || (proxyConfig.type == ProxyType::SOCKS5_PW)) {
qDebug() << Q_FUNC_INFO << "using SOCKS proxy";
proxy.setType(QNetworkProxy::Socks5Proxy);
}
else {
qDebug() << Q_FUNC_INFO << "using HTTP proxy";
proxy.setType(QNetworkProxy::HttpProxy);
}
// Authentication?
if (proxyManager->isAuthenticationRequired()) {
qDebug("Proxy requires authentication, authenticating...");
proxy.setUser(proxyConfig.username);
proxy.setPassword(proxyConfig.password);
}
}
else {
proxy.setType(QNetworkProxy::NoProxy);
}
m_networkManager.setProxy(proxy);
}
示例12: getProxy
bool connection::getProxy()
{
bool success = true;
//QSettings settings(QSettings::defaultFormat(), QSettings::UserScope, "qutim/qutim."+m_profile_name, "icqsettings");
QSettings settings(QSettings::defaultFormat(), QSettings::UserScope, "qutim/qutim."+m_profile_name+"/ICQ."+icqUin, "accountsettings");
if ( settings.value("connection/useproxy", false).toBool() )
{
quint16 proxyType = settings.value("proxy/proxyType", 0).toInt();
if ( proxyType )
{
QNetworkProxy connectionProxy;
switch( proxyType )
{
case 1:
connectionProxy.setType(QNetworkProxy::HttpProxy);
break;
case 2:
connectionProxy.setType(QNetworkProxy::Socks5Proxy);
break;
default:
break;
}
QString hostN = settings.value("proxy/host").toString();
QHostAddress addr(hostN);
if ( addr.isNull() )
{
success = false;
QHostInfo::lookupHost(hostN, const_cast<connection*>(this), SLOT(dnsResults(QHostInfo)));
}
connectionProxy.setHostName(hostN);
connectionProxy.setPort(settings.value("proxy/port", 1).toInt());
if ( settings.value("proxy/auth", false).toBool() )
{
connectionProxy.setUser(settings.value("proxy/user").toString());
connectionProxy.setPassword(settings.value("proxy/pass").toString());
}
setCurrentProxy(connectionProxy);
// currentProxy.setType(connectionProxy.type());
// currentProxy.setHostName(connectionProxy.hostName());
// currentProxy.setHostName("gggg");
// currentProxy.setPort(connectionProxy.port());
// currentProxy.setUser(connectionProxy.user());
// currentProxy.setPassword(connectionProxy.password());
}
// else {
// currentProxy.setType(QNetworkProxy::HttpCachingProxy);
// }
}
// currentProxy.setType(QNetworkProxy::NoProxy);
return success;
}
示例13: setProxy
void ignnetwork::setProxy(const QVariant &config){
/* json parsing */
QJsonParseError *err = new QJsonParseError();
QJsonDocument json = QJsonDocument::fromVariant(config);
if (err->error != 0) {
qDebug() << err->errorString();
exit (1);
}
QJsonObject jObject = json.object();
QVariantMap set_proxy = jObject.toVariantMap();
if(set_proxy["type"].toString() != ""){
QNetworkProxy proxy;
QString proxy_type = set_proxy["type"].toString();
if(proxy_type == "http"){
proxy.setType(QNetworkProxy::HttpProxy);
}
else if(proxy_type == "socks5"){
proxy.setType(QNetworkProxy::Socks5Proxy);
}
else if(proxy_type == "ftp"){
proxy.setType(QNetworkProxy::FtpCachingProxy);
}
else if(proxy_type == "httpCaching"){
proxy.setType(QNetworkProxy::HttpCachingProxy);
}
else{
qDebug()<<"Please input your type proxy (http,socks5,ftp,httpCaching)!";
}
if(set_proxy["url"].toString() != ""){
QString url = set_proxy["url"].toString();
QStringList url_proxy = url.split(":");
proxy.setHostName(url_proxy.at(0));
proxy.setPort(url_proxy.at(1).toInt());
}
else{
qDebug()<<"Please input your hostname:port Ex: 127.0.0.1:8080!";
}
if(set_proxy["username"].toString() != ""){
proxy.setUser(set_proxy["username"].toString());
}
if(set_proxy["password"].toString() != ""){
proxy.setPassword(set_proxy["password"].toString());
}
QNetworkProxy::setApplicationProxy(proxy);
}
}
示例14: handleRequest
bool SeimiServerHandler::handleRequest(Pillow::HttpConnection *connection){
QString method = connection->requestMethod();
QString path = connection->requestPath();
if(method == "GET"){
connection->writeResponse(405, Pillow::HttpHeaderCollection(),"Method 'GET' is not supprot,please use 'POST'");
return true;
}
if(path != "/doload"){
return false;
}
QEventLoop eventLoop;
SeimiPage *seimiPage=new SeimiPage(this);
QString url = connection->requestParamValue(urlP);
int renderTime = connection->requestParamValue(renderTimeP).toInt();
QString proxyStr = connection->requestParamValue(proxyP);
if(!proxyStr.isEmpty()){
QRegularExpression re("(?<protocol>http|https|socket)://(?:(?<user>\\w*):(?<password>\\w*)@)?(?<host>[\\w.]+)(:(?<port>\\d+))?");
QRegularExpressionMatch match = re.match(proxyStr);
if(match.hasMatch()){
QNetworkProxy proxy;
if(match.captured("protocol") == "socket"){
proxy.setType(QNetworkProxy::Socks5Proxy);
}else{
proxy.setType(QNetworkProxy::HttpProxy);
}
proxy.setHostName(match.captured("host"));
proxy.setPort(match.captured("port").toInt()==0?80:match.captured("port").toInt());
proxy.setUser(match.captured("user"));
proxy.setPassword(match.captured("password"));
seimiPage->setProxy(proxy);
}else {
qWarning("[seimi] proxy pattern error, proxy = %s",proxyStr.toUtf8().constData());
}
}
QString jscript = connection->requestParamValue(scriptP);
QString postParamJson = connection->requestParamValue(postParamP);
seimiPage->setScript(jscript);
seimiPage->setPostParam(postParamJson);
qInfo("[seimi] TargetUrl:%s ,RenderTime(ms):%d",url.toUtf8().constData(),renderTime);
int useCookieFlag = connection->requestParamValue(useCookieP).toInt();
seimiPage->setUseCookie(useCookieFlag==1);
QObject::connect(seimiPage,SIGNAL(loadOver()),&eventLoop,SLOT(quit()));
seimiPage->toLoad(url,renderTime);
eventLoop.exec();
Pillow::HttpHeaderCollection headers;
headers << Pillow::HttpHeader("Content-Type", "text/html;charset=utf-8");
connection->writeResponse(200, headers,seimiPage->getContent().toUtf8());
seimiPage->deleteLater();
return true;
}
示例15: locker
//-----------------------------------------------------------------------------
void
UrlFactory::_tryCorrectGoogleVersions(QNetworkAccessManager* networkManager)
{
QMutexLocker locker(&_googleVersionMutex);
if (_googleVersionRetrieved) {
return;
}
_googleVersionRetrieved = true;
if(networkManager)
{
QNetworkRequest qheader;
QNetworkProxy proxy = networkManager->proxy();
QNetworkProxy tProxy;
tProxy.setType(QNetworkProxy::DefaultProxy);
networkManager->setProxy(tProxy);
QSslConfiguration conf = qheader.sslConfiguration();
conf.setPeerVerifyMode(QSslSocket::VerifyNone);
qheader.setSslConfiguration(conf);
QString url = "http://maps.google.com/maps/api/js?v=3.2&sensor=false";
qheader.setUrl(QUrl(url));
QByteArray ua;
ua.append(getQGCMapEngine()->userAgent());
qheader.setRawHeader("User-Agent", ua);
_googleReply = networkManager->get(qheader);
connect(_googleReply, &QNetworkReply::finished, this, &UrlFactory::_googleVersionCompleted);
connect(_googleReply, &QNetworkReply::destroyed, this, &UrlFactory::_replyDestroyed);
connect(_googleReply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error),
this, &UrlFactory::_networkReplyError);
networkManager->setProxy(proxy);
}
}