Answer the question
In order to leave comments, you need to log in
How to correctly send a request from nodejs to php script?
I am doing authorization on nodejs through puff, all the code is here .
requestify.get('https://site.com/check-auth.php', {
dataType: 'json',
headers: {
'Cookie': socket.request.headers["cookie"],
'User-Agent': socket.request.headers["user-agent"],
'X-Requested-With': 'XMLHttpRequest',
// 'Content-Type': 'application/json',
}
}).then(function(response) {
// console.log(response);
var user = JSON.parse(response.getBody());
console.log('user: ', user);
socket.handshake.user = user;
next();
}, function(err){
console.log(err);
next(new Error('not authorized'));
});
{ Error: connect ECONNREFUSED 127.0.1.1:443
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.1.1',
port: 443 }
startSession();
$user = [];
try {
if(isset($_SESSION["username"]) and isset($_SESSION["password"]) and isset($_SESSION['ID_USER'])){
$user['id'] = $_SESSION['ID_USER'];
} else {
throw new Exception('not authorized');
}
echo json_encode($user);
} catch (Exception $e) {
http_response_code(404);
echo json_encode(['error' => $e->getMessage()]);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question