hello again
I have this code in node.js this code take picture in direct mode :
` const express = require('express');
const request = require("request");
const bodyParser = require("body-parser");
const app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.get("/", (req, res)=> {
res.sendFile(__dirname + "/index.html");
console.log("get request")
});
app.post("/takePicture", (req, res) => {
request({
headers: {
'content-type': 'application/json;charset=utf-8'
},
url: "http://192.168.1.1/osc/commands/execute",
method: "POST",
json: {
name: "camera.takePicture"
}
}, (error, response, body) => {
console.log(body);
res.send(body);
});
});
app.listen(3000, ()=> {
console.log("THETA Node Server running on port 3000.");
}); `
but i want this code with Authentication for client mode
if i want make Authentication in node.js what i should add in this code ??
i hope your help and thanks so much
okay problem is Solved and i will share the code In order for the benefit to prevail because I see that people in this website need help and no one know how we can make authentication with node.js
this is code :
const express = require('express');
const request = require("request");
const bodyParser = require("body-parser");
const app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.get("/", (req, res)=> {
res.sendFile(__dirname + "/index.html");
console.log("get request")
});
app.post("/authtakePicture", (req, res) => {
var options = {
uri: 'http://192.168.254.137/osc/commands/execute',
auth: {
user: 'THETAYN10113693',
pass:'10113693',
sendImmediately: false
},
headers: {'content-type': 'application/json;charset=utf-8' },
method: 'POST',
json: {
name: "camera.takePicture"
}
}
request(options, (error, response, body) => {
console.log(body);
res.send(body);
});
});
app.listen(3000, ()=> {
console.log("THETA Node Server running on port 3000.");
});
with this code we can take Picture in Client Mode with Authentication in Node.js
1 Like