单个连接中的多个请求?
是否可以使用 python httplib 在不中断连接的情况下发出多个请求? 例如,我可以将一个大文件部分上传到服务器,但在单个套接字连接中吗?
我寻找答案。但似乎没有什么事情是那么清晰明确。
任何示例/相关链接都会有所帮助。 谢谢。
Is it possible to put multiple requests without breaking the connection using python httplib?.
Like, can I upload a big file to the server in parts but in a single socket connection.
I looked for answers. But nothing seemed so clear and definite.
Any examples/related links will be helpfull.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,连接将保持打开状态,直到您使用
close()
方法将其关闭。以下示例取自 httplib 文档,展示了如何使用单个连接:
Yes, the connection stays open until you close it using the
close()
method.The following example, taken from the httplib documentation, shows how to perform multiple requests using a single connection:
您需要确保在响应中调用 .read() 函数。否则,您将收到如下错误:
如果尚未读取返回数据(即使没有返回数据,或者收到 HTTP 错误 [例如 404]),则会引发此异常。
You need to be sure to call the .read() function on your response. Otherwise you'll get an error like:
This exception is raised if the return data has not been read (even if no data is returned, or an HTTP error was recieved [a 404 for example]).