How to set the header when Image source=https://...?
Solved
QML and Qt Quick
-
I don't think there is a way to do it in QML.
What you can do is to use an QQuickImageProvider and fetch the image yourself, with correct header, using QNetworkAccessManager.
-
Image { source: "https://xxx.jpg" anchors.fill: parent fillMode: Image.PreserveAspectCrop } How to set the header?
Like this:
QNetworkRequest request; request.setRawHeader("User-Agent", "MyOwnBrowser 1.0");
Thks!
@senmx Another alternative is to use XMLHttpRequest and convert the raw image to base64(https://doc.qt.io/qt-5/qml-qtqml-qt.html#btoa-method) and set it as the Image source.
-
I don't think there is a way to do it in QML.
What you can do is to use an QQuickImageProvider and fetch the image yourself, with correct header, using QNetworkAccessManager.
-
An alternative is to set a QQmlNetworkAccessManagerFactory with QQmlEngine::setNetworkAccessManagerFactory.
You can add headers to all your requests or conditionally depending on the URL or something else.