title: iothub-errorcode: InvalidProtocolVersion
body: <p>Using the azure-iot-device sdk for node works in a standalone node program. When trying to use the same node code in a React web app, the connection to the IoT Hub fails "iothub-errorcode: InvalidProtocolVersion" with this error:</p>
  
  <pre><code>stream.js:61 WebSocket connection to 'wss://my-iothub.azure-devices.net/' failed: Error during WebSocket handshake: Unexpected response code: 400
  </code></pre>
  
  <p><strong><em>App.js</em></strong></p>
  
  <pre><code>var Protocol = require('azure-iot-device-mqtt').Mqtt;
  var Client = require('azure-iot-device').Client;
  
  var connectionString = "HostName=my-iothub.azure-devices.net;DeviceId=&lt;redacted&gt;;SharedAccessKey=&lt;redacted&gt;=";
  var client = Client.fromConnectionString(connectionString, Protocol);
  
  var connectCallback = function (err) {
    if (err) {
      console.error('Could not connect: ' + err.message);
    }
    ...
  };
  
  client.open(connectCallback);
  </code></pre>
  
  <p><strong><em>Headers (From Chrome dev tools)</em></strong></p>
  
  <pre><code>Request URL: wss://my-iothub.azure-devices.net/
  Request Method: GET
  Status Code: 400 Bad Request
  Content-Length: 158
  Content-Type: application/json; charset=utf-8
  Date: Wed, 02 Oct 2019 21:18:10 GMT
  iothub-errorcode: InvalidProtocolVersion
  Server: Microsoft-HTTPAPI/2.0
  Accept-Encoding: gzip, deflate, br
  Accept-Language: en-US,en;q=0.9
  Cache-Control: no-cache
  Connection: Upgrade
  Host: my-iothub.azure-devices.net
  Origin: http://localhost:3000
  Pragma: no-cache
  Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
  Sec-WebSocket-Key: &lt;redacted&gt;
  Sec-WebSocket-Protocol: mqtt
  Sec-WebSocket-Version: 13
  Upgrade: websocket
  User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) 
  </code></pre>
  
  <p><strong><em>Possibly related to: <a href="https://github.com/Azure/azure-sdk-for-js/issues/3473#issuecomment-499719031" rel="nofollow noreferrer">https://github.com/Azure/azure-sdk-for-js/issues/3473#issuecomment-499719031</a></em></strong></p>