java 失败:WebSocket 握手期间出错:意外响应代码:404
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32843872/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
failed: Error during WebSocket handshake: Unexpected response code: 404
提问by Pradnya
I got the error during websocket handshake. Firefox can't establish a connection to the server at ws://localhost:8082/FetchNotification/NewFile.htmlatpendpoint Is there anybody who got the same problem. I have refered the code from https://dzone.com/articles/wso2-products-resolving-err-ssl-weak-ephemeral-dh
我在 websocket 握手期间遇到错误。Firefox 无法与 ws://localhost:8082/FetchNotification/NewFile.htmlatpendpoint 的服务器建立连接 有没有人遇到同样的问题。我参考了https://dzone.com/articles/wso2-products-resolving-err-ssl-weak-ephemeral-dh 中的代码
回答by Takahiko Kawasaki
If a request to a WebSocket endpoint is correct, the endpoint returns "101 Switching Protocols". Otherwise, the endpoint will return a normal HTTP response.
如果对 WebSocket 端点的请求正确,则该端点返回“101 Switching Protocols”。否则,端点将返回正常的 HTTP 响应。
You should interpret the 404 error you got as is. That is, the path part of the URL is wrong and it is not found (404 Not Found).
您应该按原样解释 404 错误。也就是URL的路径部分错误,找不到(404 Not Found)。
回答by Guru
the url you should be using for the function call
您应该用于函数调用的网址
Echo.connect("ws://localhost:8082/FetchNotification/NewFile.html")
instead if you are using a variable like Echo.connect("ws://" + host + "/NewFile.html"), please ensure it is /FetchNotification/NewFile.html instead
相反,如果您使用的是像 Echo.connect("ws://" + host + "/NewFile.html") 这样的变量,请确保它是 /FetchNotification/NewFile.html
Otherwise in the websocket Endpoint make sure that the above url is the one you are using for
否则在 websocket Endpoint 中确保上面的 url 是你正在使用的那个
ServerEndpointConfig.Builder.create(EchoEndpoint.class,"/FetchNotification/Newfile.html").build());