SHARE
TWEET

TLS connect

WhiteMagic Sep 3rd, 2019 (edited) 160 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QtNetwork/QNetworkAccessManager>
  4. #include <QtNetwork/QNetworkReply>
  5. #include <QtNetwork/QNetworkRequest>
  6. #include <QUrl>
  7. #include <QByteArray>
  8. #include <QString>
  9. #include <QTextCodec>
  10.  
  11. MainWindow::MainWindow(QWidget *parent) :
  12.     QMainWindow(parent),
  13.     ui(new Ui::MainWindow)
  14. {
  15.     ui->setupUi(this);
  16.  
  17.     QNetworkAccessManager* manager= new QNetworkAccessManager(this);
  18.     QByteArray Request;
  19.    QUrl site("https://10.250.14.186:443/");
  20.    QString Login= "******";
  21.    QString Pass= "*****";
  22.    QString Version= "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0";
  23.  
  24.    QByteArray postData;
  25.    postData+= "a=auth" ;
  26.    postData+= "&";
  27.    postData+= "user=" + QUrl::toPercentEncoding(Login.toUtf8() );
  28.    postData+= "&";
  29.    postData+= "password=" + QUrl::toPercentEncoding(Pass.toUtf8() );
  30.  
  31.    QNetworkRequest request(site);
  32.    request.setHeader(QNetworkRequest::UserAgentHeader, Version);
  33.    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
  34.  
  35.  
  36.    QNetworkReply* reply= manager->post(request, postData);
  37.  connect (reply, SIGNAL(sslErrors(QList<QSslError>)),reply,SLOT(ignoreSslErrors()));
  38.    connect (reply, SIGNAL(finished()),this, SLOT(replyFinished()));
  39.  
  40.    //qDebug()<<QSslSocket::supportsSsl() << QSslSocket::sslLibraryBuildVersionString() <<QSslSocket::sslLibraryVersionString();
  41.  
  42.  
  43. }
  44.  
  45.  
  46.  
  47.  
  48. void MainWindow::replyFinished()
  49. {
  50.  
  51.     QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
  52.      connect (reply, SIGNAL(sslErrors(QList<QSslError>)),reply,SLOT(ignoreSslErrors()));
  53.  
  54. //    if (reply->error()== QNetworkReply::NoError)
  55. //    {
  56.  
  57.         QByteArray content= reply->readAll();
  58.          ui->textEdit->setPlainText(content.data());
  59.    // }
  60.    // else
  61.         qDebug()<<reply->errorString() <<"ska";
  62.  
  63.         reply->deleteLater();
  64. }
  65.  
  66.  
  67. MainWindow::~MainWindow()
  68. {
  69.     delete ui;
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top