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. How to set Cookie using QDesktopServices for a dynamic URL.
Forum Updated to NodeBB v4.3 + New Features

How to set Cookie using QDesktopServices for a dynamic URL.

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 1.3k Views 2 Watching
  • 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.
  • H Offline
    H Offline
    Hetal
    wrote on last edited by
    #1

    We want to open a dynamic URL in the default browser, in which we need our cookies to be set in the browser cookie for authentication purpose.

    Example:
    QDesktopServices::openUrl(QUrl(https://xys/abc.jsp));

    Thanks.

    jsulmJ JonBJ 2 Replies Last reply
    0
    • H Hetal

      We want to open a dynamic URL in the default browser, in which we need our cookies to be set in the browser cookie for authentication purpose.

      Example:
      QDesktopServices::openUrl(QUrl(https://xys/abc.jsp));

      Thanks.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Hetal Shouldn't the web page you're opening set the cookies?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • H Hetal

        We want to open a dynamic URL in the default browser, in which we need our cookies to be set in the browser cookie for authentication purpose.

        Example:
        QDesktopServices::openUrl(QUrl(https://xys/abc.jsp));

        Thanks.

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #3

        @Hetal
        It's as @jsulm says: it will be the server at that URL which will send cookies back to you (e.g. after authenticating you). You will then want to preserve those cookies and send them back in subsequent requests to that URL. For that you'll want to read https://doc.qt.io/qt-5/qnetworkcookiejar.html#details :

        Cookies are small bits of information that stateless protocols like HTTP use to maintain some persistent information across requests.

        A cookie is set by a remote server when it replies to a request and it expects the same cookie to be sent back when further requests are sent.

        H 1 Reply Last reply
        2
        • JonBJ JonB

          @Hetal
          It's as @jsulm says: it will be the server at that URL which will send cookies back to you (e.g. after authenticating you). You will then want to preserve those cookies and send them back in subsequent requests to that URL. For that you'll want to read https://doc.qt.io/qt-5/qnetworkcookiejar.html#details :

          Cookies are small bits of information that stateless protocols like HTTP use to maintain some persistent information across requests.

          A cookie is set by a remote server when it replies to a request and it expects the same cookie to be sent back when further requests are sent.

          H Offline
          H Offline
          Hetal
          wrote on last edited by
          #4

          @JonB Actually we are trying to open the URL from our own application but we want to open it it default browser not in any webview. And also we need to set the cookies for our URL authentication at the server.

          jsulmJ JonBJ 2 Replies Last reply
          0
          • H Hetal

            @JonB Actually we are trying to open the URL from our own application but we want to open it it default browser not in any webview. And also we need to set the cookies for our URL authentication at the server.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by jsulm
            #5

            @Hetal If you open the URL in a browser then the browser is responsible for accepting, storing and sending cookies to the server. It is then completely unrelated to your app. So, I'm really not sure what you want to achieve? What cookies do you want to set? The cookies will come from server to the browser...

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            2
            • H Hetal

              @JonB Actually we are trying to open the URL from our own application but we want to open it it default browser not in any webview. And also we need to set the cookies for our URL authentication at the server.

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by JonB
              #6

              @Hetal

              1. QDesktopServices::openUrl() will open in external web browser, not a Qt web view, so that's good.

              2. I still think you'll be wanting to get cookies back from the authorisation. Not pass them in. Why do you think you'd already have valid cookies to send if you're opening a new URL?

              3. I don't think you can't "pass cookies" via QDesktopServices::openUrl() (unless via ?..., I'm not sure). I think you should read https://stackoverflow.com/questions/26553802/qt-qdesktopservicesopenurl-launch-browser-with-post-values .

              EDIT No, you can't pass cookies as parameters to HTTP GET (which is what your openUrl() is doing) via ?..... They have to be set in the GET request header via Cookie: ..., e.g. see https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies .

              1 Reply Last reply
              3
              • H Offline
                H Offline
                Hetal
                wrote on last edited by
                #7

                We are using Qt 5.9.1 for a desktop application having the session Id ( which is being used for authorization), and from that we want to show a web page using the browser and in that we want to pass that session id as a cookie. Also, we can not use QWebView because of https://forum.qt.io/topic/102732/qwebview-initiating-connection-to-websocket-results-in-proxy-type-is-invalid.
                And it is hard to update Qt in the current situation.

                Please suggest.

                raven-worxR 1 Reply Last reply
                0
                • H Hetal

                  We are using Qt 5.9.1 for a desktop application having the session Id ( which is being used for authorization), and from that we want to show a web page using the browser and in that we want to pass that session id as a cookie. Also, we can not use QWebView because of https://forum.qt.io/topic/102732/qwebview-initiating-connection-to-websocket-results-in-proxy-type-is-invalid.
                  And it is hard to update Qt in the current situation.

                  Please suggest.

                  raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #8

                  @Hetal
                  just think about the vulnerability of the feature you are asking for

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  1

                  • Login

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