[英]SocketRocket and AFNetworking cookie sync
We are using SocketRocket
implementing a chat feature. 我们正在使用
SocketRocket
实现聊天功能。 But the problem is when init the SocketRocket
, it filtered by the server side login filter, so it can't do http three times handshake success. 但是问题是在初始化
SocketRocket
,它由服务器端登录过滤器过滤,因此它不能成功完成三次HTTP握手。 When we remove the server side login filter, the SocketRocket
can success talk to server-side, but server-side can't know who is the user. 当我们删除服务器端登录过滤器时,
SocketRocket
可以成功与服务器端对话,但是服务器端无法知道谁是用户。
So I'm thinking whether it is the reason the SocketRocket
don't sync cookie with AFNetworking
, cause our login is using AFNetworking
library. 所以我在想这是否是
SocketRocket
不将Cookie与AFNetworking
同步的原因,因为我们的登录名是使用AFNetworking
库。 So is there anybody know how to sync the cookies between them or if you think it is other reason, please let me know. 有没有人知道如何在它们之间同步cookie,或者如果您认为是其他原因,请告诉我。 Thanks in advance.
提前致谢。
Here is the method we used to connect to server using SocketRocket
: 这是我们使用
SocketRocket
连接到服务器的方法:
-(void)connectWebSocket{
_webSocket.delegate = nil;
_webSocket = nil;
NSString *urlString = ChatUrl;
SRWebSocket *newWebSocket = [[SRWebSocket alloc] initWithURL:[NSURL URLWithString:urlString]];
newWebSocket.delegate = self;
[newWebSocket open];
}
I just had the same problem. 我只是有同样的问题。 You need to add your cookies as request cookies on the websocket.
您需要将cookie作为请求cookie添加到websocket。 If your websocket URL is different than your login URL (eg.
wss://www.example.com
vs https://www.example.com
), you'll need to copy the cookies from the base URL. 如果您的websocket URL与登录URL不同(例如
wss://www.example.com
与https://www.example.com
),则需要从基本URL复制cookie。 For your example above: 对于上面的示例:
-(void)connectWebSocket{
_webSocket.delegate = nil;
_webSocket = nil;
NSString *urlString = ChatUrl;
SRWebSocket *newWebSocket = [[SRWebSocket alloc] initWithURL:[NSURL URLWithString:urlString]];
// Set the cookies. Need to use the base URL that your login credentials are on.
NSArray* cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:BaseUrl];
newWebSocket.requestCookies = cookies;
newWebSocket.delegate = self;
[newWebSocket open];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.