I'm using node-coap to send a coap request, and I'm initializing it with an object:
const coap = require('coap')
const url = require('url')
var b = require('buffer').Buffer
var req = {
hostname:"localhost",
method:"PUT",
pathname:"create1",
options:[{name:'Content-Format',value:b.from('text/plain')}],
body:"stringa di prova"
}
var coapReq = coap.request(req)
coapReq.write(req.body)
coapReq.end()
coapReq.on('response',function(res){
console.log('------------Risposta--------------')
console.log("Status Code:"+res.code)
})
In order to set the options in the packet, I'm using the options array instead of the setOption() method, but I'm gettin this error:
throw new Error('Unknown string to Buffer converter for option: ' + name) ^
Error: Unknown string to Buffer converter for option: 0 at module.exports.toBinary (C:\Users\Sibo\node_modules\coap\lib\option_converter.js:21:11) at OutgoingMessage.setOption (C:\Users\Sibo\node_modules\coap\lib\helpers.js:56:16) at Agent.request (C:\Users\Sibo\node_modules\coap\lib\agent.js:348:13) at Object.module.exports.request (C:\Users\Sibo\node_modules\coap\index.js:37:16) at Object. (C:\Users\Sibo\Desktop\swagger-ui\swagger-js-masterAltV2 - Copia\swagger-js-master\indexCoap.js:13:20) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3)
I'm not understanding what's wrong with my options array, someone could show me how to use it?
via SimCor
No comments:
Post a Comment