IPWorks IoT 2020 Node.js Edition

Questions / Feedback?

Post Method

Sends a POST request to the server.

Syntax

coap.post(URI, [callback])

Callback

The 'callback' parameter specifies a function which will be called when the operation completes (or an error is encountered). If the 'callback' parameter is not specified, then the method will block and will not return until the operation completes (or an error is encountered).

The callback for this method is defined as:

function(err, data){ }

'err' is the error that occurred. If there was no error, then 'err' is 'null'.

'data' is the value returned by the method.

'err' has 2 properties which hold detailed information:

err.code
err.message

Remarks

This method sends the server a POST request for the resource identified by URI. The RequestData property specifies the data that will be sent in the request. If the RequestContentFormat and/or RequestETag properties are non-empty, their values will be used to include Content-Format and Etag options in the request (respectively). Any additional options present in the RequestOption* properties will be included as well.

The format of the URI parameter is coap://hostname:port/resource. The port is optional, and if not specified will default to 5683. For instance coap://myserver/test and coap://myserver:5683/test are equivalent.

If the UseConfirmableMessages property is enabled when this method is called, the class will automatically retransmit the request message (if necessary) until it receives confirmation from the server that it was received. Note that the retransmission period is not infinite; eventually the class will assume that the message is undeliverable and time out the request.

If the Timeout property is greater than 0, this method will block until either a response is received, the specified timeout interval elapses, or (if UseConfirmableMessages is enabled) the retransmission period elapses; whichever occurs first. It will then return empty string.

If the Timeout property is 0, a record of the request will be added to the PendingRequest* properties, and this method will finish immediately, returning an Id for the request. Passing this Id to the CancelRequest method will cancel the request (assuming it is still pending at that time).

Once a response is received, or the request times out, the class will do the following:

  • Populate the Response* properties (unless the request timed out).
  • Remove the request record from the PendingRequest* properties, if necessary.
  • Fire the RequestComplete event.

Note: This method can only be called when the class is operating in client mode (i.e., when the Listening property is disabled).

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks IoT 2020 Node.js Edition - Version 20.0 [Build 8265]