노드에서 http 게시 요청 (다른 타사 서버의 로그인 요청)을 호출하고 이후의 http 요청을 위해 쿠키를 저장하려고합니다.node js http POST 저장 요청 쿠키 저장
var options = {
host: 'hostname.com',
port: '80',
path: '/login.php',
method: 'POST'
};
var data = qs.stringify({
uname: "validUsername",
password: "validPassword"
});
var req = http.request(options, function(response) {
console.log(response.statusCode);
console.log('HEADERS: ' + JSON.stringify(response.headers));
// console.log('Cookies: ' + response.getHeader("Set-Cookie"));
response.setEncoding('utf8');
response.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.write(data);
req.end();
어떻게 요청 된 서버가 보낸 응답에서 쿠키에 액세스하고 저장할 수 있습니까?
내 코드에 하나의 문제점이 있습니다. 게시물 요청과 함께 데이터를 보내는 경우 헤더 : { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': data.length } ' – Vishal