MAINWINDOW.CPP//use proxy QNetworkProxy proxy; proxy.setType(QNetworkProxy::HttpProxy); proxy.setHostName("10.12.51.72"); proxy.setPort(8080); QNetworkProxy::setApplicationProxy(proxy);//----------------------//create http request/*ask = new QHttp; QUrl url;QHttpRequestHeader header( "GET", "http://www.yandex.ru/yandsearch?text=Fucking peoples" );ask->setHost( "yandex.ru" );ask->request( header );*///ask->setHost("yandex.ru")*//*url.setUrl("http://www.vkontakte.ru/login.php");ask->setProxy(proxy);ask->setHost("vkontakte.ru");ask->get(url.path());*/ QNetworkAccessManager *manager = new QNetworkAccessManager(this); reply = manager->get(QNetworkRequest(QUrl("http://beinmusic.ru/"))); QObject::connect(reply, SIGNAL(readyRead()),this,SLOT(httpRequestFinished()));//QObject::connect(ask, SIGNAL(done( bool)),this, SLOT(httpRequestFinished( bool)));//connect buttonsvoid MainWindow::httpRequestFinished(){ if(!reply){ QMessageBox::information(this, "22", reply->error() + "\n" + reply->errorString(), QMessageBox::Ok); } else { // QString str; QByteArray data = this->reply->readAll(); //QTextCodec *codec = QTextCodec::codecForName("CP1251"); //str = codec->toUnicode(data); ui->webView->setHtml(data); QFile sl("fck.html"); sl.open(QIODevice::WriteOnly); sl.write(data); }}
if(!reply){ QMessageBox::information(this, "22", reply->error() + "\n" + reply->errorString(), QMessageBox::Ok); }
f(!reply){ QMessageBox::information(this, "22", reply->error() + "\n" + reply->errorString(), QMessageBox::Ok); }
void SomeReceiver::slotRequestFinished( QNetworkReply *pReply ){ if( pReply ) { m_lastError = pReply->error(); //-- it's a QNetworkReply::NetworkError m_strLastError = tr( "%1 (Error code %2)" ) .arg( pReply->errorString().toUtf8().data() ) .arg( pReply->error() ); if( QNetworkReply::NoError != m_lastError && ( !pReply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).isNull() && pReply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt() != 200 ) ) { qWarning() << "SomeReceiver::slotRequestFinished" << m_strLastError << m_sitePtr->getMsgTitle(); /*qDebug() << "request was:"; showRequest( &pReply->request() ); qDebug() << "reply is:"; showReply( pReply );*/ } else { //-- process reply: ... } } else { initLastError(); //-- default error notification }}