确定服务器端客户端请求的URL.套接字 [英] Determine URL of client request from server side. Socket.io

查看:99
本文介绍了确定服务器端客户端请求的URL.套接字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

引用: Socket.io客户端请求来源URL

参考: Socket.io-如何在服务器端获取客户端URL请求?

如何确定服务器端客户端请求的URL?客户请求可能来自多个域.

How do you determine the URL of client request from server side? Client request may come from multiple domains.

推荐答案

socket.io将来自发起socket.io连接的原始请求的请求对象存储在socket.request中.

socket.io stores the request object from the original request that initiated the socket.io connection in socket.request.

在此request对象上是:

request.url
request.headers

.url属性将是URL的路径(协议,主机名和端口之后的所有内容).

The .url property will be the path of the URL (everything after the protocol, hostname and port).

.headers属性将包含原始请求的所有标头.在协作浏览器中,如果该请求是跨源请求,那么将有一个origin标头,告诉您发起请求的网页域是什么(也可能存在于同一域中,原始请求也是如此).当来自受信任的浏览器(例如Chrome,IE,Safari,Firefox等)时,此原始"标头将是准确的,但如果来自其他任何类型的代理(例如,另一台服务器或脚本),则很容易被欺骗.

The .headers property will contain any headers on the original request. In a cooperating browser, if the request is a cross origin request, then there will be an origin header that tells you what the domain was of the web page that the request was initiated from (it may also be present on a same-origin request too). This "origin" header will be accurate when coming from a trusted browser such as Chrome, IE, Safari, Firefox, etc..., but can easily be spoofed if coming from any other sort of agent (such as another server or script).

这篇关于确定服务器端客户端请求的URL.套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆