mirror of
https://github.com/python/cpython.git
synced 2025-10-01 12:52:18 +00:00
Issue #28389: Merge from 3.6
This commit is contained in:
commit
f3fc3b06c4
1 changed files with 15 additions and 21 deletions
|
@ -568,33 +568,27 @@ Example of Client Usage
|
||||||
print("ERROR", v)
|
print("ERROR", v)
|
||||||
|
|
||||||
To access an XML-RPC server through a HTTP proxy, you need to define a custom
|
To access an XML-RPC server through a HTTP proxy, you need to define a custom
|
||||||
transport. The following example shows how:
|
transport. The following example shows how::
|
||||||
|
|
||||||
.. Example taken from http://lowlife.jp/nobonobo/wiki/xmlrpcwithproxy.html
|
import http.client
|
||||||
|
import xmlrpc.client
|
||||||
::
|
|
||||||
|
|
||||||
import xmlrpc.client, http.client
|
|
||||||
|
|
||||||
class ProxiedTransport(xmlrpc.client.Transport):
|
class ProxiedTransport(xmlrpc.client.Transport):
|
||||||
def set_proxy(self, proxy):
|
|
||||||
self.proxy = proxy
|
def set_proxy(self, host, port=None, headers=None):
|
||||||
|
self.proxy = host, port
|
||||||
|
self.proxy_headers = headers
|
||||||
|
|
||||||
def make_connection(self, host):
|
def make_connection(self, host):
|
||||||
self.realhost = host
|
connection = http.client.HTTPConnection(*self.proxy)
|
||||||
h = http.client.HTTPConnection(self.proxy)
|
connection.set_tunnel(host, headers=self.proxy_headers)
|
||||||
return h
|
self._connection = host, connection
|
||||||
|
return connection
|
||||||
|
|
||||||
def send_request(self, connection, handler, request_body, debug):
|
transport = ProxiedTransport()
|
||||||
connection.putrequest("POST", 'http://%s%s' % (self.realhost, handler))
|
transport.set_proxy('proxy-server', 8080)
|
||||||
|
server = xmlrpc.client.ServerProxy('http://betty.userland.com', transport=transport)
|
||||||
def send_host(self, connection, host):
|
print(server.examples.getStateName(41))
|
||||||
connection.putheader('Host', self.realhost)
|
|
||||||
|
|
||||||
p = ProxiedTransport()
|
|
||||||
p.set_proxy('proxy-server:8080')
|
|
||||||
server = xmlrpc.client.ServerProxy('http://time.xmlrpc.com/RPC2', transport=p)
|
|
||||||
print(server.currentTime.getCurrentTime())
|
|
||||||
|
|
||||||
|
|
||||||
Example of Client and Server Usage
|
Example of Client and Server Usage
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue