void MainWindow::on_loginButton_clicked(){ ui->loginButton->setEnabled(false); QNetworkAccessManager *manager = new QNetworkAccessManager(0); QNetworkRequest request; request.setUrl(QUrl("https://accounts.google.com/ServiceLogin?uilel=3&service=youtube&passive=true&continue=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26nomobiletemp%3D1%26hl%3Dru_RU%26next%3D%252F%253Fnoredirect%253D1&hl=ru_RU<mpl=sso")); request.setRawHeader("Host", "accounts.google.com"); request.setRawHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20120112 Firefox/9.0"); request.setRawHeader("Accept", "text/html"); request.setRawHeader("Accept-Charset", "windows-1251,utf-8;"); request.setRawHeader("Referer", "http://www.youtube.com/"); qDebug() << "manager"; QNetworkReply *reply = manager->get(request); QObject::connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(finishedSlot(QNetworkReply*)));}void MainWindow::finishedSlot(QNetworkReply *reply){ QNetworkAccessManager *manager = new QNetworkAccessManager(0); QString replyHtml = QString::fromUtf8(reply->readAll()); QRegExp dsh("id=\"dsh\" value=\"(.*)\""); dsh.setPatternSyntax(QRegExp::RegExp2); dsh.setMinimal(true); dsh.indexIn(replyHtml); QString dshStr = dsh.cap(1); QRegExp galx("name=\"GALX\".*value=\"(.*)\""); galx.setPatternSyntax(QRegExp::RegExp2); galx.setMinimal(true); galx.indexIn(replyHtml); QString galxStr = galx.cap(1); ui->plainTextEdit->appendPlainText(dshStr); ui->plainTextEdit->appendPlainText(galxStr); QNetworkRequest request; request.setUrl(QUrl("https://accounts.google.com/ServiceLoginAuth")); QByteArray postData; postData.append("continue=http://www.youtube.com/signin?action_handle_signin=true&nomobiletemp=1&hl=ru_RU&next=%2F"); postData.append("service=youtube"); postData.append("uilel=3"); postData.append("dsh="+dshStr); postData.append("ltmpl=sso"); postData.append("hl=ru_RU"); postData.append("ltmpl=sso"); postData.append("GALX="+galxStr); postData.append("pstMsg=1"); postData.append("dnConn="); postData.append("checkConnection=youtube:487:1"); postData.append("checkedDomains=youtube"); postData.append("timeStmp="); postData.append("secTok="); postData.append("Email=email"); postData.append("Passwd=passwd"); postData.append("signIn=Войти"); postData.append("rmShown=1"); QNetworkRequest request2; request2.setUrl(QUrl("https://accounts.google.com/ServiceLoginAuth")); request2.setRawHeader("Host", "accounts.google.com"); request2.setRawHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20120112 Firefox/9.0"); request2.setRawHeader("Accept", "text/html"); request2.setRawHeader("Accept-Charset", "windows-1251,utf-8;"); request2.setRawHeader("Referer", "https://accounts.google.com/ServiceLogin?uilel=3&service=youtube&passive=true&continue=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26nomobiletemp%3D1%26hl%3Dru_RU%26next%3D%252F%253Fnoredirect%253D1&hl=ru_RU<mpl=sso"); qDebug() << "manager"; reply = manager->post(request2, postData); QObject::connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(finishedSlot2(QNetworkReply*)));}void MainWindow::finishedSlot2(QNetworkReply *reply){ ui->plainTextEdit->appendPlainText(QString::fromUtf8(reply->readAll())); ui->plainTextEdit->appendPlainText(reply->rawHeader("Set-Cookie"));}
C++ (Qt) request.setRawHeader("Content-Type","application/atom+xml"); request.setRawHeader("Authorization","GoogleLogin auth="+getAuthToken().toUtf8()); request.setRawHeader("GData-Version","2"); request.setRawHeader("X-GData-Key","key="+getAuthKey().toUtf8());