Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Unable to Open QWebsocket with Username and Password
Forum Updated to NodeBB v4.3 + New Features

Unable to Open QWebsocket with Username and Password

Scheduled Pinned Locked Moved Unsolved General and Desktop
websocket
4 Posts 2 Posters 488 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    odriscog
    wrote on last edited by
    #1

    Hello there,

    I am currently trying to open a QWebSocket to a kdb+ process which is protected by a username and password. In order to do this from kdb+ and JavaScript, I can just provide the websocket URL as ws://username:password@host:port and the connection works as expected.

    I am trying to test this using the simple Qt example 'echoclient' here. I am using Qt 5.15.2. If I try to use the equivalent QWebSocket(QUrl(QStringLiteral("ws://username:password@host:port")) the connection simply doesn't work. The kdb+ server I am trying to connect to doesn't even register the attempted connection.

    Is it known if it is possible to use QWebSockets to create a WebSocket to a password protected process? Or is there a correct way to authenticate the user and password over HTTP prior to opening the WebSocket perhaps?

    Thank you

    Christian EhrlicherC 1 Reply Last reply
    0
    • O odriscog

      Hello there,

      I am currently trying to open a QWebSocket to a kdb+ process which is protected by a username and password. In order to do this from kdb+ and JavaScript, I can just provide the websocket URL as ws://username:password@host:port and the connection works as expected.

      I am trying to test this using the simple Qt example 'echoclient' here. I am using Qt 5.15.2. If I try to use the equivalent QWebSocket(QUrl(QStringLiteral("ws://username:password@host:port")) the connection simply doesn't work. The kdb+ server I am trying to connect to doesn't even register the attempted connection.

      Is it known if it is possible to use QWebSockets to create a WebSocket to a password protected process? Or is there a correct way to authenticate the user and password over HTTP prior to opening the WebSocket perhaps?

      Thank you

      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @odriscog said in Unable to Open QWebsocket with Username and Password:

      ws://username:password@host:port

      You should at least make sure that QUrl() can parse your url

      qDebug() << QUrl("ws://username:password@host:port")

      But I would guess you simply did not read the documentation of the QWebSocket ctor - it does not take an url as first argument

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      O 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        @odriscog said in Unable to Open QWebsocket with Username and Password:

        ws://username:password@host:port

        You should at least make sure that QUrl() can parse your url

        qDebug() << QUrl("ws://username:password@host:port")

        But I would guess you simply did not read the documentation of the QWebSocket ctor - it does not take an url as first argument

        O Offline
        O Offline
        odriscog
        wrote on last edited by
        #3

        @Christian-Ehrlicher

        My apologies that's a typo in my initial question. What I meant to say is that I am using

        EchoClient client(QUrl(QStringLiteral("ws://user:password@host:port")), debug);

        in the linked example which has the constructor

        EchoClient::EchoClient(const QUrl &url, bool debug, QObject *parent) :
            QObject(parent),
            m_url(url),
            m_debug(debug)
        {
            if (m_debug)
                qDebug() << "WebSocket server:" << url;
            connect(&m_webSocket, &QWebSocket::connected, this, &EchoClient::onConnected);
            connect(&m_webSocket, &QWebSocket::disconnected, this, &EchoClient::closed);
            connect(&m_webSocket, &QWebSocket::stateChanged, this, [](QAbstractSocket::SocketState state) { qDebug() << state ; } );
            m_webSocket.open(QUrl(url));
        }
        

        I have switched on debug in the option and the output suggests that the URL is being parsed okay, I get the following output...

        WebSocket server: QUrl("ws://user@host")
        QAbstractSocket::ConnectingState
        QAbstractSocket::UnconnectedState
        
        Christian EhrlicherC 1 Reply Last reply
        0
        • O odriscog

          @Christian-Ehrlicher

          My apologies that's a typo in my initial question. What I meant to say is that I am using

          EchoClient client(QUrl(QStringLiteral("ws://user:password@host:port")), debug);

          in the linked example which has the constructor

          EchoClient::EchoClient(const QUrl &url, bool debug, QObject *parent) :
              QObject(parent),
              m_url(url),
              m_debug(debug)
          {
              if (m_debug)
                  qDebug() << "WebSocket server:" << url;
              connect(&m_webSocket, &QWebSocket::connected, this, &EchoClient::onConnected);
              connect(&m_webSocket, &QWebSocket::disconnected, this, &EchoClient::closed);
              connect(&m_webSocket, &QWebSocket::stateChanged, this, [](QAbstractSocket::SocketState state) { qDebug() << state ; } );
              m_webSocket.open(QUrl(url));
          }
          

          I have switched on debug in the option and the output suggests that the URL is being parsed okay, I get the following output...

          WebSocket server: QUrl("ws://user@host")
          QAbstractSocket::ConnectingState
          QAbstractSocket::UnconnectedState
          
          Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          QWebSocket and QUrl have so many functions to check if they're valid or not or what's currently going on - you should use them.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved