ile tanımlama bilgisi ayarlanamıyor Node js; Node ile çerezin nasıl kurulacağını ve ayarlanacağını anlamaya çalışıyorum. Visual Studio kullanıyorum ve otomatik olarak oluşturulmuş katıştırılmış IIS Express kullanıyorum. Orada benim server.js sunucu kodu:Node js
var express = require('express');
var cookieParser = require('cookie-parser')
var app = express();
app.use(cookieParser())
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:61342');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
res.setHeader('Access-Control-Allow-Credentials', true);
next();
});
app.get('/setCookie/:param', function (req, res) {
res.cookie('testCookie', req.params.param);
console.log('cookie created!');
res.send();
});
var server = app.listen(8001, 'localhost', function() {
var host = server.address().address
var port = server.address().port
console.log("Server listening at http://%s:%s", host, port)
});
Ve bu istemci kodu:
function server() {
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "http://localhost:8001/setCookie/cookie1", true);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
alert("ok");
}
}
xmlhttp.send();
}
I (sadece test için) bir düğmeye tıkladığınızda bu görevi görüyordu diyoruz. localhost: 8001/getCookie/cookie1 yazıyorsa, doğru olarak tanımlama bilgisini (tarayıcı konsolunda görebilir, document.cookie yazabilirim), ayarlıyorum ancak projemi localhost üzerinde çalıştırıyorsam: 61342/ve
Request URL:http://localhost:8001/setCookie/cookie1
Request Method:GET
Status Code:200 OK
Remote Address:127.0.0.1:8001
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:X-Requested-With,content-type
Access-Control-Allow-Methods:GET, POST, OPTIONS, PUT, PATCH, DELETE
Access-Control-Allow-Origin:http://localhost:61342
Connection:keep-alive
Set-Cookie:testCookie=cookie1; Path=/
ama tarayıcı konsol document.cookie üzerinde yazarken ben bir şey görmüyorum: function sunucusu() call butonuna tıklayın, bu yanıt almak. Bunu nasıl çözebilirim? Sabrınız için teşekkürler