HTTP Headers
Pythonxmlrpclib
ライブラリを使用してカスタムを送信するにはどうすればよいですか??http_headers
メソッドを呼び出すときに、特別なカスタムを送信する必要がありRPC
ます。
2925 次
1 に答える
13
サブクラスxmlrpclib.Transport
化して、それを引数としてに渡すことができますServerProxy
。オーバーライドする方法を選択すると(私が選択しましたsend_content
)、設定されます。
# simple test program (from the XML-RPC specification)
from xmlrpclib import ServerProxy, Transport, Error
class SpecialTransport(Transport):
def send_content(self, connection, request_body):
print "Add your headers here!"
connection.putheader("Content-Type", "text/xml")
connection.putheader("Content-Length", str(len(request_body)))
connection.endheaders()
if request_body:
connection.send(request_body)
# server = ServerProxy("http://localhost:8000") # local server
server = ServerProxy("http://betty.userland.com", transport=SpecialTransport())
print server
try:
print server.examples.getStateName(41)
except Error, v:
print "ERROR", v
于 2011-01-16T21:13:48.550 に答える