blob: 90c918ddbbd27845dc1d839e08c71a8cd0f863f0 (
plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
//![0]
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import "request.js" as XHR
ApplicationWindow {
width: 640
height: 640
visible: true
ColumnLayout {
anchors.fill: parent
RowLayout {
Layout.fillWidth: true
TextField {
id: urlTextField
text: "https://www.example.com/index.html"
Layout.fillWidth: true
}
Button {
text: qsTr("Send!")
onClicked: XHR.sendRequest(urlTextField.text, function(response) {
statusTextField.text = response.status;
let isPlainText = response.contentType.length === 0
contentTypeTextField.text = isPlainText ? "text" : response.contentType;
if (isPlainText)
contentTextArea.text = response.content;
});
}
}
GridLayout {
columns: 2
Layout.fillWidth: true
Label {
text: qsTr("Status code")
Layout.fillWidth: true
}
Label {
text: qsTr("Response type")
Layout.fillWidth: true
}
TextField {
id: statusTextField
Layout.fillWidth: true
}
TextField {
id: contentTypeTextField
Layout.fillWidth: true
}
}
Flickable {
clip: true
contentWidth: contentTextArea.width
contentHeight: contentTextArea.height
Text {
id: contentTextArea
}
Layout.fillWidth: true
Layout.fillHeight: true
ScrollBar.vertical: ScrollBar {}
ScrollBar.horizontal: ScrollBar {}
}
}
}
//![0]
|