HttpRequest¶
Description¶
The HttpRequest object represents a HTTP request which can be sent to a server at a given URL (url). All common methods (GET, PUT, POST, DELETE) are supported. The HTTP headers can be defined through the headers property. When transferring data to the server the HttpContent object in the content property needs to be prepared accordingly. The received response (headers, status code and data) is accessible through the response property.
› Inherits: | Object |
---|
Properties¶
allowPipelining¶
This property holds whether the HTTP client is allowed to use HTTP pipelining with this request.
› Type: | Boolean |
---|---|
› Default: | false |
› Signal: | allowPipeliningChanged() |
› Attributes: | Writable |
content¶
This property holds the content which to send to the server (PUT/POST requests only). If headers does not contain a HttpHeader object with HttpHeader.type = HttpHeader.ContentType the request will be sent with an additional content type header with an automatically determined value depending on HttpContent.type.
› Type: | HttpContent |
---|---|
› Signal: | contentChanged() |
› Attributes: | Writable |
error¶
This property holds the most recently occurred error or HttpRequest.NoError if no error occurred. If the same error occurs multiple times this property does not change. Use the errorOccurred() signal to detect multiple occurrences of the same error.
› Type: | Error |
---|---|
› Signal: | errorChanged() |
› Attributes: | Readonly |
errorString¶
This property holds the current human readable error string corresponding to the current value in the error property. It may include additional information such as failure reasons or locations.
› Type: | String |
---|---|
› Signal: | errorStringChanged() |
› Attributes: | Readonly |
followRedirects¶
This property holds whether the HTTP client should automatically follow a HTTP redirect response or not. Currently redirects that are insecure, that is redirecting from “https” to “http” protocol, are not allowed.
› Type: | Boolean |
---|---|
› Default: | false |
› Signal: | followRedirectsChanged() |
› Attributes: | Writable |
headers¶
This property holds a list of header objects to use when sending a HTTP request.
› Type: | List<HttpHeader> |
---|---|
› Signal: | headersChanged() |
› Attributes: | Readonly |
response¶
This property holds the last received response for a request sent through this object.
› Type: | HttpResponse |
---|---|
› Signal: | responseChanged() |
› Attributes: | Readonly |
url¶
This property holds the URL which to send a request for.
› Type: | String |
---|---|
› Signal: | urlChanged() |
› Attributes: | Writable |
Methods¶
del()¶
This method sends a HTTP request with the DELETE method to the server. It’s mainly used for deleting resources at the given URL.
See RFC2616 Section 9.7 for details.
get()¶
This method sends a HTTP request with the GET method to the server. It’s mainly used for downloading resources at the given URL.
See RFC2616 Section 9.3 for details.
post()¶
This method sends a HTTP request with the POST method to the server. It’s mainly used for annotation of existing resources, providing a block of data, such as the result of submitting a form, to a data-handling process or extending a database through an append operation.
See RFC2616 Section 9.5 for details.
put()¶
This method sends a HTTP request with the PUT method to the server. It’s mainly used for storing resources under the given URL.
See RFC2616 Section 9.6 for details.
Signals¶
errorOccurred()¶
This signal is emitted whenever an error has occurred, regardless of whether the error property has changed or not. In contrast to the change notification signal of the error property this signal is also emitted several times if a certain error occurs several times in succession.
headersDataChanged(SignedInteger index)¶
This signal is emitted whenever the List.dataChanged() signal is emitted, i.e. the item at index
in the headers list itself emitted the dataChanged() signal.
responseReceived()¶
This signal is emitted when a response is received for a request represented by this object. It’s identical to the HttpResponse.received() signal but provided for convenience.
Enumerations¶
Error¶
This enumeration describes all errors which can occur in HttpRequest objects. The most recently occurred error is stored in the error property.
Name | Value | Description |
---|---|---|
HttpRequest.NoError |
0 |
No error occurred or was detected. |
HttpRequest.ConnectionRefusedError |
1 |
The remote server refused the connection (the server is not accepting requests). |
HttpRequest.RemoteHostClosedError |
2 |
The remote server closed the connection prematurely, before the entire response was received and processed. |
HttpRequest.HostNotFoundError |
3 |
The remote host name was not found (invalid hostname). |
HttpRequest.TimeoutError |
4 |
The connection to the remote server timed out. |
HttpRequest.OperationCanceledError |
5 |
The operation was canceled before it was finished. |
HttpRequest.SslHandshakeFailedError |
6 |
The SSL/TLS handshake failed and the encrypted channel could not be established. |
HttpRequest.TemporaryNetworkFailureError |
7 |
The connection was broken due to disconnection from the network, however the system has initiated roaming to another access point. The request should be resubmitted and will be processed as soon as the connection is re-established. |
HttpRequest.NetworkSessionFailedError |
8 |
The connection was broken due to disconnection from the network or failure to start the network. |
HttpRequest.BackgroundRequestNotAllowedError |
9 |
The background request is not currently allowed due to platform policy. |
HttpRequest.TooManyRedirectsError |
10 |
While following redirects, the maximum limit was reached. The limit is by default set to 50. |
HttpRequest.InsecureRedirectError |
11 |
while following redirects, the HTTP client detected a redirect from a encrypted protocol (https) to an unencrypted. |
HttpRequest.UnknownNetworkError |
99 |
An unknown network-related error was detected. |
HttpRequest.ProxyConnectionRefusedError |
101 |
The connection to the proxy server was refused (the proxy server is not accepting requests). |
HttpRequest.ProxyConnectionClosedError |
102 |
The proxy server closed the connection prematurely, before the entire response was received and processed. |
HttpRequest.ProxyNotFoundError |
103 |
The proxy host name was not found (invalid proxy hostname). |
HttpRequest.ProxyTimeoutError |
104 |
The connection to the proxy timed out or the proxy did not reply in time to the request sent. |
HttpRequest.ProxyAuthenticationRequiredError |
105 |
The proxy requires authentication in order to honour the request but did not accept any credentials offered (if any). |
HttpRequest.UnknownProxyError |
199 |
An unknown proxy-related error was detected. |
HttpRequest.ContentAccessDenied |
201 |
The access to the remote content was denied (similar to HTTP error 403). |
HttpRequest.ContentOperationNotPermittedError |
202 |
The operation requested on the remote content is not permitted. |
HttpRequest.ContentNotFoundError |
203 |
The remote content was not found at the server (similar to HTTP error 404). |
HttpRequest.AuthenticationRequiredError |
204 |
The remote server requires authentication to serve the content but the credentials provided were not accepted (if any). |
HttpRequest.ContentReSendError |
205 |
The request needed to be sent again, but this failed for example because the upload data could not be read a second time. |
HttpRequest.ContentConflictError |
206 |
The request could not be completed due to a conflict with the current state of the resource. |
HttpRequest.ContentGoneError |
207 |
The requested resource is no longer available at the server. |
HttpRequest.UnknownContentError |
299 |
An unknown error related to the remote content was detected. |
HttpRequest.ProtocolUnknownError |
301 |
The HTTP client cannot honor the request because the protocol is not known. |
HttpRequest.ProtocolInvalidOperationError |
302 |
The requested operation is invalid for this protocol. |
HttpRequest.ProtocolFailure |
399 |
A breakdown in protocol was detected (parsing error, invalid or unexpected responses, etc.). |
HttpRequest.InternalServerError |
401 |
The server encountered an unexpected condition which prevented it from fulfilling the request. |
HttpRequest.OperationNotImplementedError |
402 |
The server does not support the functionality required to fulfill the request. |
HttpRequest.ServiceUnavailableError |
403 |
The server is unable to handle the request at this time. |
HttpRequest.UnknownServerError |
499 |
An unknown error related to the server response was detected. |
Example¶
import InCore.Foundation 2.5
import InCore.Http 2.5
Application {
HttpRequest {
id: simpleRequest
url: "https://inhub.de"
onResponseReceived: console.log("Response for GET:", response.statusCode, response.content.data)
}
HttpRequest {
id: postTest
url: "https://httpbin.org/post"
content: HttpContent {
type: HttpContent.PlainText
data: "InCore.Http POST Example"
}
onResponseReceived: console.log("Response for POST:", response.statusCode, response.content.data["data"])
}
HttpRequest {
id: putTest
url: "https://httpbin.org/put"
content: HttpContent {
type: HttpContent.PlainText
data: "InCore.Http PUT Example"
}
response.autoDetectDataTypeFromContentType: false
onResponseReceived: console.log("Response for PUT:", response.statusCode, response.content.data)
}
onCompleted: {
simpleRequest.get();
postTest.post();
putTest.put();
}
}