1

如果请求包含诸如以下的标头:

Authorization: Digest username="Mufasa",
                      realm="testrealm@host.com",
                      nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093"

节点是否有任何内置方法来提取键值对?还是我应该只使用string.split

4

1 回答 1

-1

使用 URL 模块http://nodejs.org/api/url.html

Example: http://www.host.com:8080/path?name=daniel

接受一个 URL 字符串,并返回一个对象。
url.parse(urlStr, [parseQueryString], [slashesDenoteHost])

var server = http.createServer(function (request, response) {
  var queryData = url.parse(request.url, true).query;
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end('Hello ' + queryData.name + '\n');
}

在此示例中,名称映射到 daniel。

于 2013-06-12T14:08:21.233 回答