session close added
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
const http = require('http')
|
||||
|
||||
module.exports = class http_client {
|
||||
constructor(ip, port) {
|
||||
this.#ip = ip
|
||||
this.#port = port
|
||||
}
|
||||
async post(data, callback_answer, callback_error) {
|
||||
// Build the post string from an object
|
||||
|
||||
// An object of options to indicate where to post to
|
||||
var post_options = {
|
||||
host: this.#ip,
|
||||
port: this.#port,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'applicaiton/json',
|
||||
'Content-Length': Buffer.byteLength(data)
|
||||
}
|
||||
}
|
||||
// Set up the request
|
||||
var request = http.request(post_options, function(res) {
|
||||
res.setEncoding('utf8')
|
||||
res.on('data', async function (answer) {
|
||||
callback_answer(answer)
|
||||
})
|
||||
})
|
||||
request.on('error', function(e) {
|
||||
callback_error(e)
|
||||
})
|
||||
// post the data
|
||||
request.write(data)
|
||||
request.end()
|
||||
}
|
||||
#ip
|
||||
#port
|
||||
}
|
||||
Reference in New Issue
Block a user