标签:
一个简单的httpserver。接收get请求,并返回解析之后的数据。
以下是服务的代码:
var http = require("http"); var url = require("url"); var querystring = require("querystring"); http.createServer(function (request, response) { var objectUrl = url.parse(request.url); var objectQuery = querystring.parse(objectUrl.query); response.writeHead(200, {"content-type": "text/html"}); response.write("<h1>objectUrl</h1>"); for (var i in objectUrl) { if (typeof (objectUrl[i]) != "function") response.write(i + ":" + objectUrl[i] + "<br>"); } response.write("<h1>objectQuery</h1>"); for (var i in objectQuery) { response.write(i + ":" + objectQuery[i] + "<br>"); } response.end(); }).listen(8080, '192.168.33.98');
使用node执行这个文件,然后再浏览器中输出:http://192.168.33.98:8080/?name=xulidong&passward=123456,192.168.33.98是我的电脑ip。
执行结果如图:
标签:
原文地址:http://www.cnblogs.com/bhlsheji/p/5377532.html