最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何从节点响应对象获取请求URL?

网站源码admin18浏览0评论

如何从节点响应对象获取请求URL?

如何从节点响应对象获取请求URL?

[当您使用Node发出http / https请求(或使用诸如simple-get的包装器)时,您将返回simple-geterrresponse对象。在回调中,有没有办法获取原始请求的URL,主机,URL等?

示例(使用data):

simple-get's concat
回答如下:

您可以从基础套接字(由于[C​​0]只是包装simple-get-模块的包装器)和const get = require('simple-get') get.concat('http://example', function (err, res, data) { if (err) throw err console.log(res.statusCode) // 200 console.log(res.headers) // {...} // i want "http://example" at this point console.log(res.uri) // undefined console.log(res.url) // undefined console.log(res.path) // undefined console.log(res.host) // undefined }) -对象获得一些信息:

simple-get
发布评论

评论列表(0)

  1. 暂无评论