Unexpected response code 426

2019-02-18 16:14发布

问题:

I am using Tomcat websockets and it is working fine in all browsers except in Safari where it is throwing Unexpected response code 426 error.
I went through web inspector and tried to google it to find solution to this issue.
But did not find any solution to it.
I am using Safari 5.1.7. Any help would be greatly appreciated.
Thanks in Advance

回答1:

The 426 response code on upgrade is appropriate for when your websocket client is not conforming to the WebSocket standard RFC-6455.

See Section 4.2.2. Sending the Server's Opening Handshake. http://tools.ietf.org/html/rfc6455#section-4.2.2

   /version/
      The |Sec-WebSocket-Version| header field in the client's
      handshake includes the version of the WebSocket Protocol with
      which the client is attempting to communicate.  If this
      version does not match a version understood by the server, the
      server MUST abort the WebSocket handshake described in this
      section and instead send an appropriate HTTP error code (such
      as 426 Upgrade Required) and a |Sec-WebSocket-Version| header
      field indicating the version(s) the server is capable of
      understanding.

What is going on, is that Safari 5.x isn't using the final WebSocket spec, but rather an early experimental draft version, something that tomcat does not correctly support. Few production servers do anymore.

For more information see What browsers support HTML5 WebSocket API? and http://caniuse.com/websockets