使用 Qt 进行基本身份验证 (QNetworkAccessManager)
我试图从我的 Qt 应用程序执行 Twitter 的基本身份验证。我使用 QNetworkAccessManager。但我在这方面找不到任何帮助。
但我发现了一个名为 qsoapmanager 的程序,它通过标头以 base64 形式传递凭据。也许我可以通过在 QNetowrkRequest 中设置标头来使用 QNAM 来做到这一点。但我没能找到方法。
在 qsoapman 源代码中,标头设置如下:
QHttpRequestHeader header;
header.setValue( "Authorization", QString( "Basic " ).append( auth.data() ) );
Can I do just that with QNAM/QNReq or is there a better way?
I was trying to perform basic authentication for Twitter from my Qt app. I use QNetworkAccessManager. But I couldn't find any help on this.
But I found a program called qsoapmanager which passes credentials in base64 through the header. Maybe I can do this with QNAM by setting header in QNetowrkRequest. But I failed to find a way.
In qsoapman source, header is set like this:
QHttpRequestHeader header;
header.setValue( "Authorization", QString( "Basic " ).append( auth.data() ) );
Can I do just that with QNAM/QNReq or is there a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
推荐的方法是连接到
authenticationRequired
从那里发出信号并设置凭据。The recommended way is to connect to the
authenticationRequired
signal and set the credentials from there.只是正常使用 qNetworkAccessManager 但添加
到您的请求。
示例:
`
Just using qNetworkAccessManager normally but add
to your request.
Example:
`
但是,如果您只想通过设置标头值来完成此操作,请按以下步骤操作:
But if you want to do it by just setting the header value, here's how you can do that: