mirror of
https://github.com/arnaucube/raspberryGPIOhtmlserver.git
synced 2026-02-08 12:16:42 +01:00
servidor funciona, gpio desabilitat
This commit is contained in:
67
node_modules/formidable/example/json.js
generated
vendored
Executable file
67
node_modules/formidable/example/json.js
generated
vendored
Executable file
@@ -0,0 +1,67 @@
|
||||
var common = require('../test/common'),
|
||||
http = require('http'),
|
||||
util = require('util'),
|
||||
formidable = common.formidable,
|
||||
Buffer = require('buffer').Buffer,
|
||||
port = common.port,
|
||||
server;
|
||||
|
||||
server = http.createServer(function(req, res) {
|
||||
if (req.method !== 'POST') {
|
||||
res.writeHead(200, {'content-type': 'text/plain'})
|
||||
res.end('Please POST a JSON payload to http://localhost:'+port+'/')
|
||||
return;
|
||||
}
|
||||
|
||||
var form = new formidable.IncomingForm(),
|
||||
fields = {};
|
||||
|
||||
form
|
||||
.on('error', function(err) {
|
||||
res.writeHead(500, {'content-type': 'text/plain'});
|
||||
res.end('error:\n\n'+util.inspect(err));
|
||||
console.error(err);
|
||||
})
|
||||
.on('field', function(field, value) {
|
||||
console.log(field, value);
|
||||
fields[field] = value;
|
||||
})
|
||||
.on('end', function() {
|
||||
console.log('-> post done');
|
||||
res.writeHead(200, {'content-type': 'text/plain'});
|
||||
res.end('received fields:\n\n '+util.inspect(fields));
|
||||
});
|
||||
form.parse(req);
|
||||
});
|
||||
server.listen(port);
|
||||
|
||||
console.log('listening on http://localhost:'+port+'/');
|
||||
|
||||
|
||||
var request = http.request({
|
||||
host: 'localhost',
|
||||
path: '/',
|
||||
port: port,
|
||||
method: 'POST',
|
||||
headers: { 'content-type':'application/json', 'content-length':48 }
|
||||
}, function(response) {
|
||||
var data = '';
|
||||
console.log('\nServer responded with:');
|
||||
console.log('Status:', response.statusCode);
|
||||
response.pipe(process.stdout);
|
||||
response.on('end', function() {
|
||||
console.log('\n')
|
||||
process.exit();
|
||||
});
|
||||
// response.on('data', function(chunk) {
|
||||
// data += chunk.toString('utf8');
|
||||
// });
|
||||
// response.on('end', function() {
|
||||
// console.log('Response Data:')
|
||||
// console.log(data);
|
||||
// process.exit();
|
||||
// });
|
||||
})
|
||||
|
||||
request.write('{"numbers":[1,2,3,4,5],"nested":{"key":"value"}}');
|
||||
request.end();
|
||||
Reference in New Issue
Block a user