How to set Cookie using QDesktopServices for a dynamic URL.
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.
@Hetal Shouldn't the web page you're opening set the cookies?
JonB last edited by
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.
@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.
@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...
JonB last edited by JonB
QDesktopServices::openUrl()will open in external web browser, not a Qt web view, so that's good.
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?
I don't think you can't "pass cookies" 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
GETrequest header via
Cookie: ..., e.g. see https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies .
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.
just think about the vulnerability of the feature you are asking for