2013-03-20 4 views
2
을 입력합니다.

쿠키를 설정하고 픽셀을 클라이언트에 다시 보내야하는 node.js (웹 비콘 픽셀 기준)에 스크립트를 작성했습니다.node.js가 쿠키를 설정하고 응답으로

내 문제는 코드에서 GIF를 보내는 부분을 제거하면 쿠키가 설정되어 있지 않지만이 두 가지를 함께 설정하여 GIF를 다시 보낼 수있는 방법을 찾을 수 없습니다.

http = require('http'); 
url = require('url'); 

http.createServer(function(req, res){ 
    var requestURL = url.parse(req.url, true); 
    if (requestURL.pathname == '/log.gif') { 

     // Write a Cookie 
     res.writeHead(200, { 
      'Set-Cookie' : 'id='+requestURL.query.id+'; expires=' + new Date(new Date().getTime()+86409000).toUTCString() 
     }); 

     var imgHex = '47494638396101000100800000dbdfef00000021f90401000000002c00000000010001000002024401003b'; 
     var imgBinary = new Buffer(imgHex, 'hex'); 
     res.writeHead(200, {'Content-Type': 'image/gif' }); 
     res.end(imgBinary, 'binary'); 


    } else { 
     res.writeHead(200, {'Content-Type': 'text/plain' }); 
     res.end(''); 
    } 
}).listen(8080); 
+1

htt p : //nodejs.org/api/http.html#http_response_writehead_statuscode_reasonphrase_headers : _ "이 메서드는 메시지에서 한 번만 호출하면됩니다."_ Content-type을 설정하는 res.WriteHead 호출에 Set-Cookie 헤더를 추가하기 만하면됩니다. – CBroe

+0

@CBroe node.js에 초보자 예를 보여줄 수 있습니까? –

+0

링크 된 페이지의 예제는 이미 두 개의 헤더를 설정하고 있습니다. – CBroe

답변

관련 문제