<span style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">Hello</span><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">The code suggests it does - but I can't get it to work.</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif"><div>class ProxyAgent(_AgentBase):</div><div> """</div><div> An HTTP agent able to cross HTTP proxies.</div>
<div><br></div><div> @ivar _proxyEndpoint: The endpoint used to connect to the proxy.</div><div><br></div><div> @since: 11.1</div><div> """</div><div><br></div><div> def __init__(self, endpoint, reactor=None, pool=None):</div>
<div> if reactor is None:</div><div> from twisted.internet import reactor</div><div> _AgentBase.__init__(self, reactor, pool)</div><div> self._proxyEndpoint = endpoint</div><div><br></div>
<div>
<br></div><div> def request(self, method, uri, headers=None, bodyProducer=None):</div><div> """</div><div> Issue a new request via the configured proxy.</div><div> """</div>
<div> # Cache *all* connections under the same key, since we are only</div><div> # connecting to a single destination, the proxy:</div><div> key = ("http-proxy", self._proxyEndpoint)</div><div>
<br></div><div> # To support proxying HTTPS via CONNECT, we will use key</div><div> # ("http-proxy-CONNECT", scheme, host, port), and an endpoint that</div><div> # wraps _proxyEndpoint with an additional callback to do the CONNECT.</div>
<div> return self._requestWithEndpoint(key, self._proxyEndpoint, method,</div><div> _parse(uri), headers, bodyProducer,</div><div> uri)</div>
</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif"><br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">The "Using a http proxy" - <a href="http://twistedmatrix.com/documents/current/web/howto/client.html" style="color:rgb(17,85,204)" target="_blank">http://twistedmatrix.com/documents/current/web/howto/client.html</a> works, provided the target url is http ( not https as shown in the example ).</div>
<div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">I'm attempting to adapt this example to confirm https proxing is possible</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif"><div>from twisted.python.log import err</div><div>from twisted.web.client import ProxyAgent</div><div>
from twisted.internet import reactor</div><div>from twisted.internet.endpoints import TCP4ClientEndpoint</div><div><br></div><div>def display(response):</div><div> print "Received response"</div><div> print response</div>
<div><br></div><div>def main():</div><div> endpoint = TCP4ClientEndpoint(reactor, "localhost", 8000)</div><div> agent = ProxyAgent(endpoint)</div><div> d = agent.request("GET", "<a href="https://example.com/" style="color:rgb(17,85,204)" target="_blank">https://example.com/</a>")</div>
<div> d.addCallbacks(display, err)</div><div> d.addCallback(lambda ignored: reactor.stop())</div><div> reactor.run()</div><div><br></div><div>if __name__ == "__main__":</div><div> main()</div></div>
<div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">I've tried changing the endpoint to SSL4ClientEndpoint without success.</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">Any help, much appreciated</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
- G</div>