Qt QWebView类自定义User-Agent
有没有一种简单的方法来设置 QWebView 类正在使用的用户代理?
我发现搜索的唯一相关链接是这个
http://www.qtforum.org/article/27073/how-to-set-user-agent-in-qwebview.html
我现在正在学习 C++/Qt,但我不太明白什么是那个网站上有解释。也许有人知道一个简单的方法来做到这一点?或者可以帮助我理解该代码吗?
Is there an easy way to setup the User-Agent the QWebView class is using?
The only relevant link I found searching was this
http://www.qtforum.org/article/27073/how-to-set-user-agent-in-qwebview.html
I'm learning C++/Qt right now and I don't really understant what's explained on that website. Maybe someone knows an easy way to do it? Or can help me understand that code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Qt 允许您提供基于 URL 的用户代理,而不是无论 URL 是什么都提供单个用户代理。然后,想法是在创建新网页时随时返回用户代理:
为了使用该页面而不是创建的标准页面,您可以在发出请求之前在浏览器控制对象上设置该页面:
我实际上会期望某个地方存在一个工厂,可以保证创建的网页始终属于某种类型,但我没有看到。
另一个选择应该是在 QNetworkRequest 中设置用户代理标头:
您实际上想要检查是否它是 toAscii() 或 toUtf8() 或其他变体之一,因为我不确定 HTTP 标准到底允许什么。
Qt allows you to provide a user agent based on the URL rather than a single user agent no matter what the URL is. The idea then is to return the user agent any time a new webpage is created:
In order to use that page instead of the standard page that is created, you can set that page on the browser control object before making the request:
I would actually expect a factory to be present somewhere that will guarantee that the webpage created is always of a certain type, but I didn't see one.
Yet another option should be to set the user agent header within the QNetworkRequest:
You would actually want to check whether it's
toAscii()
ortoUtf8()
or one of the other variants as I'm not sure exactly what the HTTP standard allows.简单地,
simply,