节点响应对象获取请求URL?"/>
如何从节点响应对象获取请求URL?
[当您使用Node发出http / https请求(或使用诸如simple-get
的包装器)时,您将返回simple-get
,err
和response
对象。在回调中,有没有办法获取原始请求的URL,主机,URL等?
示例(使用data
):
simple-get
's concat
回答如下:您可以从基础套接字(由于[C0]只是包装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
更多推荐
如何从节点响应对象获取请求URL?
发布评论