18,356
社区成员
发帖
与我相关
我的任务
分享
#include <QtCore/QCoreApplication>
#include <QtNetwork>
#include <QSsl>
#include <QSslSocket>
#include <iostream>
#include <QByteArray>
#include <QString>
#include <QFile>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSslSocket socket;
socket.setProtocol(QSsl::AnyProtocol);
QFile certFile;
certFile.setFileName("./cacert.pem");
QSslCertificate cert(&certFile);
socket.addCaCertificate(cert);
socket.connectToHostEncrypted(host,port);
//socket.ignoreSslErrors();
if (!socket.waitForEncrypted())
{
cout<<"ERROR:"<<socket.errorString().toStdString();
}
cout<< socket.readAll().data();
QByteArray packet;
packet.append("hello world");
socket.write(packet);
socket.flush();
while (socket.waitForReadyRead())
cout<< socket.readAll().data();
end:
return a.exec();
}