Qt 和 HTTP 下载
我正在开发一个类,它将实现某个即时消息协议的客户端。
我需要首先发出一个 HTTP 请求,然后读取数据并使用从第一个请求接收到的已处理数据发出另一个 HTTP 请求,只有在第二个请求之后我才能打开到服务器的 tcp 套接字。 执行此操作的最佳方法(最佳 QT 方法?)是什么,因为我还没有找到阻止 HTTP 请求结束的方法。我正在考虑在这部分使用 libcurl,但仅为此使用另一个库似乎有点过分了。
I am working on a class that will implement a client for a certain Instant Messaging protocol.
I need to first make a HTTP request, then read the data and make another HTTP request with the processed data received from the first request and only after the second request i can open a tcp socket to the server.
What is the best way(best QT way?) to go about doing this as i haven't found a way to block until HTTP request is over. I was considering using libcurl for this part but it seems a overkill to use another lib only for this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
QHttp
将发送一组信号来通知请求的状态。例如,您可以将requestFinished()
信号连接到一个插槽,该插槽将处理该信号并启动第二个请求。或者作为另一种解决方案,
您可以巧妙地使用锁定结构,例如 QMutex 并通过实现您自己的阻塞请求方法来包装 QHttp,这将一次允许一个请求。但我认为就你的情况而言,第一种方法更好。
QHttp
will send a set of signals to notify the state of a request. You may for example connectrequestFinished()
signal to a slot that will process it and start your second request.Idea in pseudo-qt
Or as another solution you can smartly use locking structures such as
QMutex
and wrap QHttp by implementing your own blocking request method, that will allow one request at time. But I think that in your case the first approach is better.