HttpHeader
Description
The HttpHeader object represents a single HTTP header which is sent to or received from HTTP servers through HttpRequest and HttpResponse objects.
- › Inherits:
Overview
Properties
Methods
Signals
Enumerations
Properties
customHeader
This property holds the name of a custom HTTP header field which is used when type is set to HttpHeader.Custom.
- › Type:
String
- › Signal:
customHeaderChanged()
- › Attributes:
Writable
data
This property holds the data for the HTTP header represented by this object. The data type depends on the header type but usually a string can be used. Use a DateTime object for the header types HttpHeader.LastModified and HttpHeader.IfModifiedSince. This allows dealing with dates easily and let them being converted to properly formatted date strings automatically.
- › Type:
Variant
- › Signal:
dataChanged()
- › Attributes:
Writable
type
This property holds the type of the HTTP header represented by this object.
- › Type:
- › Default:
- › Signal:
typeChanged()
- › Attributes:
Writable
Enumerations
Type
This enumeration describes the supported HTTP header types as described in RFC 2616 Section 14.
Name |
Value |
Description |
|---|---|---|
|
|
Corresponds to the HTTP Content-Type header and contains a string containing the media (MIME) type and any auxiliary data (for instance, charset). |
|
|
Corresponds to the HTTP Content-Length header and contains the length in bytes of the data transmitted. |
|
|
Corresponds to the HTTP Location header and contains a URL representing the actual location of the data, including the destination URL in case of redirections. |
|
|
Corresponds to the HTTP Last-Modified header and contains a DateTime object representing the last modification date of the contents. |
|
|
Corresponds to the HTTP Content-Disposition header and contains a string containing the disposition type (for instance, attachment) and a parameter (for instance, filename). |
|
|
The User-Agent header sent by HTTP clients. |
|
|
The Server header received by HTTP clients. |
|
|
Corresponds to the HTTP If-Modified-Since header and contains a DateTime object. It is usually added to a HttpRequest object. The server shall send a 304 (Not Modified) response if the resource has not changed since this time. |
|
|
Corresponds to the HTTP ETag header and contains a QString representing the last modification state of the contents. |
|
|
Corresponds to the HTTP If-Match header and contains a StringList. It is usually added to a HttpRequest object. The server shall send a 412 (Precondition Failed) response if the resource does not match. |
|
|
Corresponds to the HTTP If-None-Match header and contains a StringList. It is usually added to a HttpRequest object. The server shall send a 304 (Not Modified) response if the resource does match. |
|
|
Corresponds to a custem HTTP header. The content of the customHeader property is used for the HTTP header name field. |
Example
import InCore.Foundation 2.5
import InCore.Http 2.5
Application {
id: app
MeasurementGroup {
id: sensorGroup
Measurement {
id: temperatureSensor
unit: "°C"
data: 20 + Math.random() * 10
}
Measurement {
id: pressureSensor
unit: "Pa"
data: 100000 + Math.random() * 10000
siPrefix: Pressure.Kilo
}
}
Serializer {
id: sensorSerializer
source: sensorGroup
}
HttpRequest {
id: headerTest
url: "https://httpbin.org/post"
content: HttpContent {
type: HttpContent.Json
data: sensorSerializer.data
}
HttpHeader {
type: HttpHeader.UserAgent
data: "InCore HTTP Client"
}
HttpHeader {
customHeader: "InCore-DeviceId"
data: system.deviceId
}
response.autoDetectDataTypeFromContentType: false
onResponseReceived: console.log("Response for POST:", response.statusCode, response.content.data)
}
onCompleted: {
headerTest.post();
}
}