C++ (Qt)INCLUDEPATH += $$[QT_INSTALL_PREFIX]/src/3rdparty/zlib
C++ (Qt)QByteArray uncompress(const QByteArray &);
C++ (Qt)#include <zlib.h> QNetworkAccessManager qnam; QNetworkProxy proxy; if (proxySOCKS5) { proxy.setType(QNetworkProxy::Socks5Proxy); } else if (proxyHTTP) { proxy.setType(QNetworkProxy::HttpProxy); } if (proxyOne.isEmpty() && !proxyNO) { qDebug() << "Нема прокси"; return; } if (!proxyNO) { QStringList proxyList = proxyOne.trimmed().split(":"); QString proxyHostName = proxyList[0]; quint16 proxyPort = QString(proxyList[1]).toInt(); proxy.setHostName(proxyHostName); proxy.setPort(proxyPort); qnam.setProxy(proxy); } RemadedNetworkCookieJar *cookieJar = new RemadedNetworkCookieJar(); qnam.setCookieJar(cookieJar); QNetworkRequest request; request.setRawHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"); request.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); request.setRawHeader("Accept-Language", "ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3"); request.setRawHeader("Accept-Encoding", "gzip, deflate"); request.setRawHeader("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7"); request.setRawHeader("Connection", "keep-alive"); request.setUrl(QUrl("http://mail.ru")); QNetworkReply *reply = qnam.get(request); QEventLoop loop; connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); reply->deleteLater(); if(reply->error() != QNetworkReply::NoError) { qDebug() << reply->errorString(); } QString answer = QString::fromLocal8Bit(uncompress(reply->readAll())); // если кодировка сайта Windows-1251. если локаль в другой кодировке, будут иероглифы. как без привязки к локале из Windows-1251 преобразовать не догнал QString answer = QString::fromUtf8(uncompress(reply->readAll())); // charset=UTF-8 QByteArray Class::uncompress(const QByteArray &data){ if (data.size() <= 4) { qWarning("gUncompress: Input data is truncated"); return QByteArray(); } QByteArray result; int ret; z_stream strm; static const int CHUNK_SIZE = 1024; char out[CHUNK_SIZE]; /* allocate inflate state */ strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; strm.avail_in = data.size(); strm.next_in = (Bytef*)(data.data()); ret = inflateInit2(&strm, 15 + 32); // gzip decoding if (ret != Z_OK) return QByteArray(); // run inflate() do { strm.avail_out = CHUNK_SIZE; strm.next_out = (Bytef*)(out); ret = inflate(&strm, Z_NO_FLUSH); Q_ASSERT(ret != Z_STREAM_ERROR); // state not clobbered switch (ret) { case Z_NEED_DICT: ret = Z_DATA_ERROR; // and fall through case Z_DATA_ERROR: case Z_MEM_ERROR: (void)inflateEnd(&strm); return QByteArray(); } result.append(out, CHUNK_SIZE - strm.avail_out); } while (strm.avail_out == 0); // clean up and return inflateEnd(&strm); return result;}