Russian Qt Forum
Май 03, 2024, 12:08 *
Добро пожаловать, Гость. Пожалуйста, войдите или зарегистрируйтесь.
Вам не пришло письмо с кодом активации?

Войти
 
  Начало   Форум  WIKI (Вики)FAQ Помощь Поиск Войти Регистрация  

Страниц: [1]   Вниз
  Печать  
Автор Тема: Qt & https  (Прочитано 8199 раз)
QCasper
Гость
« : Июнь 04, 2007, 08:21 »

Научите, пож., гонять данные по https. Я так полагаю, что надо использовать вновь прибывший QSslSocket... На этом мои догадки заканчиваются.
Я попытался использовать QHttp::setSocket(new QSslSocket(this)), и делать get на 443 порт, но запрос стал формироваться неверно. Вобщем я хочу работатть с классом QHttp так же как обычно (get, post), но чтобы данные криптовались ssl, подскажите, пожалуйста.
Записан
crocus
Гость
« Ответ #1 : Июнь 05, 2007, 02:08 »

http://labs.trolltech.com/blogs/2007/03/26/ssl-with-5-lines-of-code/
Записан
QCasper
Гость
« Ответ #2 : Июнь 05, 2007, 13:12 »

Цитата: "crocus"


Этот код есть и в асистанте, но там нет ни слова про связку QSslSocket с QHttp.
Записан
alexis
Гость
« Ответ #3 : Июнь 05, 2007, 13:18 »

замени QSocket на QsslSocket
что-то вроде этого:
Код:

QHttp *http = new QHttp( this );
QsslSocket *ssl = new QsslSocket( this );
http->setSocket( ssl );
Записан
SABROG
Гость
« Ответ #4 : Июнь 05, 2007, 13:18 »

Это ?

Цитировать

enum QHttp::ConnectionMode
QHttp::ConnectionModeHttps

The Https protocol is used and the connection is encrypted using SSL.

When using the Https mode, care should be taken to connect to the sslErrors signal, and handle possible Ssl errors.
This enum was introduced in Qt 4.3.
See also QSslSocket.


Погуглил немного:

Код:

/****************************************************************************
**
** Copyright (C) 2007 Urs Wolfer <uwolfer @ fwo.ch>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU Library General Public License
** along with this library; see the file COPYING.LIB.  If not, write to
** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
** Boston, MA 02110-1301, USA.
**
****************************************************************************/
 
#include <QHttp>
#include <QByteArray>
#include <QFile>
#include <QTextStream>
#include <QDebug>
 
#include "smssender.h"
 
SmsSender::SmsSender(QObject *parent)
    : QObject(parent)
{
    http = new QHttp("idn.ethz.ch", QHttp::ConnectionModeHttps, 0, this);
    connect(http, SIGNAL(requestFinished(int,bool)), SLOT(slotFinished(int,bool)));
    connect(http, SIGNAL(stateChanged(int)), SLOT(slotChanged(int)));
 
    http->get("/cgi-bin/sms/main.cgi/iibfgipqmqnntvvrqsps/_top");
 
}
 
void SmsSender::login()
{
    QByteArray parms("");
    parms.clear();
    parms.append("_login_page=1");
    parms.append("&"+ loginLogin+"=Login");
    parms.append("&_username=psoukal");
    parms.append("&"+ loginPw+"=guetetagwohl");
 
    http->post("/cgi-bin/sms/main.cgi/" + loginUrl + "/_top", parms);
 
 
 
    parms.clear();
    parms.append("originator=text");
    parms.append("&textoriginator=TEst");
    parms.append("&phone=0798103355");
    parms.append("&messagetext=hallo%20test");
    parms.append("&send=Send");
    http->post("/cgi-bin/sms/task1.fastpl/psoukal_" + loginUrl  + "/_top", parms);
 
}
 
void SmsSender::slotChanged(int id)
{
//     qDebug(error ? "error" : "ok");
//     qDebug(qPrintable(QString::number((int)http->error())));
//     qDebug(qPrintable(http->readAll()));
//     qDebug("changed");
//     qDebug(qPrintable(QString::number(id)));
//     qDebug(http->readAll());
}
 
void SmsSender::slotFinished(int id, bool error)
{
    qDebug(error ? "error" : "ok");
    qDebug(qPrintable(QString::number((int)http->error())));
//     qDebug(qPrintable(http->readAll()));
    qDebug(qPrintable(QString::number(id)));
//     qDebug(http->readAll());
// QString output(http->readAll().data());
    if (id == 2)
 
        qDebug(http->readAll().data());
 
    if (id == 3)
 
        qDebug(http->readAll().data());
 
 
    if (id == 1) {
//         qDebug(http->readAll().data());
 
        QString output(http->readAll().data());
 
        int j = 0;
 
        while ((j = output.indexOf("main.cgi", j)) != -1) {
//          qDebug() << "Found <b> tag at index position" << j;
            ++j;
            QString o1 = output.right(output.length() - j -8);
            o1 = o1.left(20);
            loginUrl = o1;
 
            qDebug(o1.toLatin1().data());
        }
 
        j = 0;
 
 
        while ((j = output.indexOf("tabindex=\"1\" name=", j)) != -1) {
//          qDebug() << "Found <b> tag at index position" << j;
            ++j;
            QString o1 = output.right(output.length() - j -18);
            o1 = o1.left(8);
            loginLogin = o1;
            qDebug(o1.toLatin1().data());
        }
 
        j = 0;
 
 
        while ((j = output.indexOf("type=\"password\" name=", j)) != -1) {
//          qDebug() << "Found <b> tag at index position" << j;
            ++j;
            QString o1 = output.right(output.length() - j -21);
            o1 = o1.left(8);
            loginPw = o1;
            qDebug(o1.toLatin1().data());
        }
 
        login();
}
 
}
Записан
QCasper
Гость
« Ответ #5 : Июнь 05, 2007, 13:47 »

Цитата: "alexis"
замени QSocket на QsslSocket
что-то вроде этого:
Код:

QHttp *http = new QHttp( this );
QsslSocket *ssl = new QsslSocket( this );
http->setSocket( ssl );


Я же говорю, делал так - запрос некорректно формируется.

добавлено спустя 1 минуту:

 
Цитата: "SABROG"
Это ?

Цитировать

enum QHttp::ConnectionMode
QHttp::ConnectionModeHttps

The Https protocol is used and the connection is encrypted using SSL.

When using the Https mode, care should be taken to connect to the sslErrors signal, and handle possible Ssl errors.
This enum was introduced in Qt 4.3.
See also QSslSocket.

А вот это уже больше похоже, тем более что в "нагугленном" коде тоже этот приём используется. Не приметил то я нового enum'a в QHttp Улыбающийся
Записан
qtuser
Гость
« Ответ #6 : Август 27, 2007, 10:05 »

Помогите разобраться. Имеем хост, к которому есть доступ через https (простая форма, ввожу логин, пароль, жму "отправить" и получаю доступ). Вот данные формы:
событие формы: form action="get_login" method="POST"
поле логина: input type="text" name="login"
поле пароля: input type="text" name="password"
кнопка "отправить": input type="submit" value="send"
Пытаюсь сделать это программно:
...
http = new QHttp("имя_сервера", QHttp::ConnectionModeHttps, 443, this);
QByteArray parms("login=mylogin&password=mypassword");
http->post("/get_login", parms);
...
В ответ получаю страницу, информирующую о неудачном входе. Объясните, как правильно работать c https через QHttp.
ЗЫ логин и пароль корректные, вместо "имя_сервера" - реальный хост.
Записан
Страниц: [1]   Вверх
  Печать  
 
Перейти в:  


Страница сгенерирована за 0.045 секунд. Запросов: 20.