日期:2014-05-16  浏览次数:20469 次

nodejs笔记2——请求路由

对于不同的URL请求,服务器应该有不同的反应。我们要为路由提供请求的URL和其他需要的GET及POST参数,随后路由需要根据这些数据来执行相应的代码。我们需要的所有数据都会包含在request对象中,该对象作为onRequest()回调函数的第一个参数传递。为了解析这些数据,需要调用额外的模块,分别是url和querystring模块。

URL:This module has utilities for URL resolution and parsing. Call require('url') to use it.

Parsed URL objects have some or all of the following fields, depending on whether or not they exist in the URL string. Any parts that are not in the URL string will not be in the parsed object. Examples are shown for the URL

'http://user:pass@host.com:8080/p/a/t/h?query=string#hash'

  • href: The full URL that was originally parsed. Both the protocol and host are lowercased.

    Example: 'http://user:pass@host.com:8080/p/a/t/h?query=string#hash'

  • protocol: The request protocol, lowercased.

    Example: 'http:'

  • host: The full lowercased host portion of the URL, including port information.

    Example: 'host.com:8080'

友情链接: 爱易网 云虚拟主机技术 云服务器技术 程序设计技术 开发网站 APP开发教程
Copyright © 2013-2024 爱易网页 当前在线:1047人  网站在15时38分14秒内访问总人数:173188人 当前 100.00%  粤ICP备18100884号-2