如何在 QtWebEngine QML 应用程序中设置用户代理
How to set User Agent in QtWebEngine QML application
NOTE: I was able to do that on QtWebKit QML using the QtWebView extension. Here I am interested in using QtWebEngine.
我的简单测试应用程序
import QtQuick 2.1
import QtQuick.Controls 1.1
import QtWebEngine 1.0
ApplicationWindow {
width: 800
height: 600
color: "lightgray"
visible: true
WebEngineView {
id: webview
url: "http://stackexchange.com/"
anchors.fill: parent
}
}
如何传递不同的 User Agent string?
我也有兴趣使用 QtWebEngine。我可以建议您使用 QtWebEngine 开发人员 Trello.
正如您在 5.5 的待办事项中看到的那样 这是 currently under development 并且可以在 5.5 中完成。
从 Qt 5.5 开始,您可以设置 WebEngineProfile.userAgent 属性。
// 导入 QtWebEngine 1.4
WebEngineView {
id: webview
url: "http://stackexchange.com/"
anchors.fill: parent
profile: WebEngineProfile{
httpUserAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1"
}
}
NOTE: I was able to do that on QtWebKit QML using the QtWebView extension. Here I am interested in using QtWebEngine.
我的简单测试应用程序
import QtQuick 2.1
import QtQuick.Controls 1.1
import QtWebEngine 1.0
ApplicationWindow {
width: 800
height: 600
color: "lightgray"
visible: true
WebEngineView {
id: webview
url: "http://stackexchange.com/"
anchors.fill: parent
}
}
如何传递不同的 User Agent string?
我也有兴趣使用 QtWebEngine。我可以建议您使用 QtWebEngine 开发人员 Trello.
正如您在 5.5 的待办事项中看到的那样 这是 currently under development 并且可以在 5.5 中完成。
从 Qt 5.5 开始,您可以设置 WebEngineProfile.userAgent 属性。
// 导入 QtWebEngine 1.4
WebEngineView {
id: webview
url: "http://stackexchange.com/"
anchors.fill: parent
profile: WebEngineProfile{
httpUserAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1"
}
}