0
我是Node.js的新手。 我寫了簡單的Node.js程序來打印hello world。 它工作正常。如何使用Node.js訪問查詢字符串
現在,當我通過與沿查詢字符串,然後它給出了一個錯誤
Node.js的
var http = require("http");
http.createServer(function (request, response) {
// Send the HTTP header
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});
// Send the response body as "Hello World"
response.end('Hello World\n'+request.q);
}).listen(8081);
// Console will print the message
console.log('Server running at http://127.0.0.1:8081/');
查詢從瀏覽器
http://127.0.0.1:8081/?q=MrX
它給
Hello World
undefined
嘗試request.body –
http://stackoverflow.com/questions/6912584/how-to-get-get-query-string-variables-in-表達-JS-上節點-JS?RQ = 1 – Pogrindis