I've setup a Node.js server that gets some contact form data and forwards it to my email. I'd like to be able to forward some information about the user's browser along with the form data.
我已经设置了一个Node.js服务器来获取一些联系表单数据并将其转发到我的电子邮件中。我希望能够转发有关用户浏览器的一些信息以及表单数据。
Is any of that information contained in the request object in some form ? Kind of like the navigator.userAgent string that is available on the client ?
请求对象中是否包含某种形式的信息?有点像客户端上可用的navigator.userAgent字符串?
Or should I include that string in the data sent out, manually, myself?
或者我应该在发送的数据中包含该字符串,手动,我自己?
I was thinking of something like :
我想的是:
var httpServer = http.createServer(function (request, response)
{
var browserID = request.navigator.userAgent;
});
Thanks!
谢谢!
1 个解决方案
#1
3
I was testing this out myself in express, and you can find the user-agent string in:
我在express中自己测试了这个,你可以在以下位置找到用户代理字符串:
request.header['user-agent']
and you can see it in the HTTP specification in 14.43 here.
你可以在14.43的HTTP规范中看到它。
In the future, you can simply examine the request
object either with console.log()
or with the debugger and see exactly what's in it. I find that is often ultimately more educational than trying to find things in documentation somewhere.
将来,您可以使用console.log()或使用调试器来检查请求对象,并查看其中的确切内容。我发现这通常比试图在某个地方的文档中找到东西更具教育意义。
#1
3
I was testing this out myself in express, and you can find the user-agent string in:
我在express中自己测试了这个,你可以在以下位置找到用户代理字符串:
request.header['user-agent']
and you can see it in the HTTP specification in 14.43 here.
你可以在14.43的HTTP规范中看到它。
In the future, you can simply examine the request
object either with console.log()
or with the debugger and see exactly what's in it. I find that is often ultimately more educational than trying to find things in documentation somewhere.
将来,您可以使用console.log()或使用调试器来检查请求对象,并查看其中的确切内容。我发现这通常比试图在某个地方的文档中找到东西更具教育意义。