#include "ui_mainwindow.h"
#include <QTcpSocket>
#include <QUrl>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QTcpSocket socket;
QUrl url("https://mstdn.jp/api/v1/timelines/public");
QString hostName = "mstdn.jp";
socket.connectToHost(hostName, 80);
socket.write("GET " + url.toEncoded(QUrl::RemoveScheme | QUrl::RemoveAuthority) + " HTTP/1.1\r\nHost: " + hostName.toUtf8() + "\r\n\r\n");
socket.waitForReadyRead(1000000);
QString data = QString(socket.readAll());
ui->textEdit->setText(data);
socket.close();
}
MainWindow::~MainWindow()
{
delete ui;
}
[結果]
HTTP/1.1 301 Moved Permanently
Date: Wed, 26 Apr 2017 09:53:29 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: __cfduid=d876325d0b88d8b09e238204d873fdc201493200409; expires=Thu, 26-Apr-18 09:53:29 GMT; path=/; domain=.mstdn.jp; HttpOnly
Location: https://mstdn.jp/api/v1/timelines/public
Server: cloudflare-nginx
CF-RAY: 3558a7bef61c133b-NRT
b2
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>
0