扭曲的http客户端 [英] twisted http client
问题描述
我正在描述Twisted的HTTP客户端的使用示例。
I am after an example describing the usage of Twisted's HTTP Client.
阅读优秀的关于内幕的博文Twisted ,我理解工厂和协议组件如何发挥作用,但我不清楚如何在整个客户流程中引入请求。
After reading the excellent blog post on the internals of Twisted, I understand how the "Factory" and "Protocol" components play their role but I am unclear on how to introduce "Request" in the overall Client flow.
更具体地说,我需要能够使用Twisted对远程服务器执行HTTP GET和POST请求。
More specifically, I need to be able to perform HTTP GET and POST requests to a remote server using Twisted.
更新:在讨论了irc #twisted / #python之后,似乎 twisted.web2
正逐渐消失,有利于增强 twisted.web <上的功能/ code>例如代理。
Updated: after a discussion on irc #twisted / #python, it seems that twisted.web2
is fading away in favor of beefing up functionality on twisted.web
e.g. Agent.
推荐答案
从Twisted 9.0开始,实际上有两个HTTP客户端可用。旧版本具有相当多的功能,例如自动跟踪重定向,解释cookie标题等。您可以在此处找到其用法的示例:
As of Twisted 9.0, there are actually two HTTP clients available. The older one has quite a few features, such as automatically following redirects, interpreting cookie headers, etc. You can find an example of its usage here:
http://twistedmatrix.com/documents/current/web/examples/
( getpage.py
和 dlpage.py
)
不幸的是,旧客户端提供的界面使许多常见任务变得困难。例如,使用 getPage
,您无法检查任意响应标头。
Unfortunately, the interface presented by the older client makes a number of common tasks difficult. For example, using getPage
, you cannot examine arbitrary response headers.
较新的HTTP客户端尚未作为与旧版本相同,但它提供了一个界面,旨在消除 getPage
的限制。它还旨在更容易扩展和定制。您可以在此处找到描述其用法的文档:
The newer HTTP client isn't yet as featureful as the old one, but it presents an interface intended to eliminate the limitations of getPage
. It is also intended to be more easily extended and customized. You can find a document describing its usage here:
http://twistedmatrix.com/documents/current/web/howto/client.html
这篇关于扭曲的http客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!