Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for WebAssembly
  4. Unable to open WebSocket with a request parameter
QtWS25 Last Chance

Unable to open WebSocket with a request parameter

Scheduled Pinned Locked Moved Unsolved Qt for WebAssembly
5 Posts 4 Posters 642 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.
  • I Offline
    I Offline
    imahgin
    wrote on last edited by imahgin
    #1

    Hi,
    I'm developing a desktop and WASM app that opens a wss using a request instead of an url

    void open(const QNetworkRequest &request)
    

    I need this approach because the server expects an Authentication Bearer token when request opening the socket.

    QNetworkRequest request(url);
    QString header = "Bearer " + myToken;
    request.setRawHeader("Authorization", header.toLocal8Bit());
    this->wsocket->open(request);
    

    This works as expected on desktop platform, but doesn't work on WASM, where the server doesn't receive any request at all.

    I've tried it on several SDK version (5.15.2, 6.4.2, 6.5.3 and 6.6.0) with their respectives emscripten versions, but the same occurs.

    Any suggestion -appart from sending the token using some other way-?
    Is it a Qt related issue or an emscripten limitation?

    Thks in advance

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Delphi251189
      wrote on last edited by
      #2

      Hi.
      I faced the same issue...and the reasons why I need headers in request are the same too...
      At least the issue presents in Qt 6.6.3.
      Do You have any solutions?

      1 Reply Last reply
      0
      • I Offline
        I Offline
        imahgin
        wrote on last edited by imahgin
        #3

        Hi,
        Nope, not available from WASM
        Needed to conduct the authorization in some other way
        I'll check again on latest SDK 6.7.1 and related emscripten

        1 Reply Last reply
        0
        • 8Observer88 Offline
          8Observer88 Offline
          8Observer8
          wrote on last edited by 8Observer8
          #4

          I had a problem with connection with the server on the free Glitch hosting from WASM. I solved it by setting User-Agent. I use Qt 6.6.3. Maybe it will help:

          QUrl url("wss://merciful-regal-soursop.glitch.me");
          
          QNetworkRequest request;
          request.setUrl(url);
          request.setRawHeader(QByteArray("User-Agent"),
              QByteArray("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
              "(KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"));
          m_webSocket.open(request);
          

          And I had another problem with connection from Android. I was solved it like this: Get data with Qt client from deployed Node.js server using WebSockets

          1 Reply Last reply
          0
          • M Offline
            M Offline
            monica345
            wrote on last edited by
            #5
            This post is deleted!
            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