forked from Elioxx/Webclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebclient.cpp
36 lines (28 loc) · 796 Bytes
/
webclient.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "webclient.h"
Webclient::Webclient(QWidget *parent) :
QWidget(parent)
{
setupUi(this);
m_socket = new QTcpSocket(this);
connect(m_socket, &QTcpSocket::connected, this, &Webclient::connected);
connect(m_socket, &QTcpSocket::readyRead, this, &Webclient::readyRead);
}
void Webclient::connected()
{
m_socket->write(QString("GET / HTTP/1.1\r\nHost:" + m_hostname + "\r\n\r\n").toLocal8Bit());
}
void Webclient::readyRead()
{
output->setText(m_socket->readAll());
m_socket->disconnectFromHost();
}
void Webclient::on_startButton_clicked()
{
output->clear();
m_hostname = hostname->text();
m_socket->connectToHost(m_hostname,m_port);
if(!m_socket->waitForConnected(5000))
{
output->setText("connection not available");
}
}