var http=require("http"); var message=[ "HelloWorld", "From a basic Node.js server", "Take Luck" ]; http.createServer((req,res)=>{ res.setHeader("Content-Type","text/html"); res.writeHeader(200); res.write("<html><head><title>Simple Http Serever</title></head>"); res.write("<body>"); for(let i in message){ res.write(`\n<h1><mark>${message[i]}</mark></h1></mark>`); } res.end("\n</body></html>"); console.log("Look me ! I succeed ! ! !"); }).listen(8080); var options={ hostname:"www.soul.com", port:"8080" }; function handleResponse(response){ var serverData=""; response.on("data",(chunk)=>{ serverData+=chunk; }); response.on("end",()=>{ console.log(`Response Status:${response.statusCode}`); console.log(`Response Headers:${response.headers}`); console.log(serverData); }); } http.get(options,(response)=>{ handleResponse(response); });
时间: 2024-12-29 12:33:43