【问题标题】:In node.js How do I get the protocol of a request object?在 node.js 中如何获取请求对象的协议?
【发布时间】:2017-07-05 00:52:29
【问题描述】:
const URL = require('url').URL;
const myURL = new URL('https://example.org/foo');

console.log(myURL.href);     // https://example.org/foo
console.log(myURL.protocol); // https:
console.log(myURL.hostname); // example.org
console.log(myURL.pathname); // /foo

但是如何获取用户向服务器发出的请求 url ???

【问题讨论】:

  • 你能做req.header吗
  • 它显示了标题中的所有内容。
  • 其实是request.protocol,就是我要找的。不过谢谢你的关心,我很感激。
  • Node 是为 http 开发的...所以您的节点应用程序处理的请求无论如何都是 http(或 https)...

标签: node.js


【解决方案1】:

只需通过request.protocol 喜欢

    exports.nameOfFunction = function(request, response){
    var proto = request.protocol;
    console.log(proto);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-14
    • 2016-05-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-14
    • 2015-08-15
    • 2019-08-10
    相关资源
    最近更新 更多