HttpResponse
The HttpResponse object allows returning data when sending uplink data through HTTP.
Properties
### statusCode (int) The statusCode property allows indicating the HTTP response status code. The default value for this property is 200 (OK).
Examples
This example shows the creation of an HTTP response with status 200 and JSON content.
var httpResponse = new HttpReponse();
httpResponse.statusCode = 200;
httpResponse.contentType = "application/json";
httpResponse.content.setAsJson({ result: ultimo });### contentType (string) The contentType property indicates the type of content that will be returned in the HTTP request.
Examples
This example shows the creation of an HTTP response with status 200 and JSON content.
var httpResponse = new HttpReponse();
httpResponse.statusCode = 200;
httpResponse.contentType = "application/json";
httpResponse.content.setAsJson({ result: ultimo });Methods
### content.setAsJson(object) The content.setAsJson() method allows setting the response content in JSON format, with the data of the given object as parameter.
Parameters
- object (object): this parameter contains the object to be sent as a response. The object will be converted to JSON format.
Example
This example shows the creation of an HTTP response with status 200 and JSON content.
var httpResponse = new HttpReponse();
httpResponse.statusCode = 200;
httpResponse.contentType = "application/json";
httpResponse.content.setAsJson({ result: ultimo });### content.setAsString(text) The content.setAsString() method allows setting the response content using the given text as parameter.
Parameters
- text (string): this parameter contains the text to be sent as a response.
Example
This example shows the creation of an HTTP response with status 200 and text content.
var httpResponse = new HttpReponse();
httpResponse.statusCode = 200;
httpResponse.contentType = "text/plain";
httpResponse.content.setAsString("This is some text");### content.setAsBytes(bytes) The content.setAsBytes() method allows setting the response content in binary form, using the given data as parameter.
Parameters
- bytes (int[]): this parameter contains the byte array to be sent as a response.
Example
This example shows the creation of an HTTP response with status 200 and binary content of 5 bytes.
var httpResponse = new HttpReponse();
httpResponse.statusCode = 200;
httpResponse.contentType = "application/octet-stream";
httpResponse.content.setAsBytes([1, 2, 3, 4, 5]);