Closed tomasimartin closed 4 years ago
Hello @tomasimartin, Thank you for using the StompClientLib. Actually it is a problem with your backend side.
Here is What Is 422 Unprocessable Entity? article about the bad response. Please contact with your backend devs :) However, I'm also here to help, discuss your problem :) Have fun!
hello @WrathChaos The same API is used in Kotlin (Android) and also in Java, on the same url. It works perfectly on both environments.
As I said in my previous message, I used another library to make websocket, and with the same url on that library it works.
That's why I'm focusing my research here. Has anyone ever encountered this problem?
Actually there are some similar issues. Some related issues:
I know that it could work on Android however, iOS requires so many different things to do :( I believe that you need to research about it. Currently, it works with my example project & other recent projects. Have you ever tried with simple example project?
@WrathChaos thanks for your quick feedback, we found the problem internally, it was a server side headers check. I hope I didn't disturb you too much. Well, hello from France. you can close this issue
@tomasimartin I'm glad to hear that :) You're always welcome to come & brainstorm :) Please feel free to ask anything :)
Hi @WrathChaos ,
we found out where the problem came from, when connecting there is an http call where we pass in the header
HEADER={{"host":["dev.myserver.fr"], "sec-websocket-protocol":["], "sec-websocket-key":["M6rALuZT9o3NRROXksQ==="], "sec-websocket-version":["13"], "upgrade":["websocket"], "origin":["http://dev.myserver.fr], "connection":["Upgrade"]}
but I don't find in this header the parameters I added during the connection:
let headerWS = ["deviceId":deviceToken]
socketClient.openSocketWithURLRequest(request: NSURLRequest(url: url as URL), delegate: self, connectionHeaders: headerWS)
it can come from the SocketRocket library, the initial call to the connection is made without taking into account the header.
I'm not good enough in objective-c to modify the lib myself.
Do you have an idea to pass my header ["deviceId":deviceToken]
, during the initial call
Hey @tomasimartin, I'm gonna try it with modifying SocketRocket but I need some time to test it. ObjC is really a pain :D
To get around my problem, I passed the header differently, like this
if let url = NSURL(string: hostws) {
var deviceTokenManager = DeviceTokenManager()
if let deviceToken = deviceTokenManager.retreiveToken() {
let headerWS = ["deviceId":deviceToken]
let request = NSMutableURLRequest(url: url as URL)
request.setValue(deviceToken, forHTTPHeaderField: "deviceId")
socketClient.openSocketWithURLRequest(request: request, delegate: self, connectionHeaders: headerWS)
}
}
@tomasimartin Hello. I have got the same problem.
Error Domain=SRWebSocketErrorDomain Code=2132 "received bad response code from server 403" UserInfo={NSLocalizedDescription=received bad response code from server 403, HTTPResponseStatusCode=403}
As you said there is a server side problem (checking headers). Could you please give me more detailed information.
Thanks in advance!
@WrathChaos , Can you please tell me what is reason behind this error.
Error Domain=SRWebSocketErrorDomain Code=2132 "received bad response code from server 403" UserInfo={NSLocalizedDescription=received bad response code from server 403, HTTPResponseStatusCode=403}
I have checked with backend server, and also verify with Android its also working fine, when i am trying to connect socket from iOS getting error.
I have tried all cases like as, URL : ws://{server_url}/ws/websocket URL : wss://{server_url}/ws/websocket URL : http://{server_url}/ws/websocket URL : https://{server_url}/ws/websocket
But i am not getting result. can you please explain where i am wrong and missing something from my end ?
Thanks in advance.
@tusharMistri Any luck?
why was this issue marked as closed?
I am getting the same issue.
EDIT: Never mind :D Unrelated issue. Cors settings are not shared between HTTP and Stomp/WS in Spring (my backend)
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/websocket")
.setAllowedOriginPatterns("*");
}
Hi. I get an error while trying to connect to websocket, here is the code:
Response:
And if I use another "Starscream" library, it connects very well with the same url, but I need the "STOMP" part that this other library doesn't have
Do you have any ideas why that might be the case?