4

HTTP HeadersPythonxmlrpclibライブラリを使用してカスタムを送信するにはどうすればよいですか??http_headersメソッドを呼び出すときに、特別なカスタムを送信する必要がありRPCます。

4

1 に答える 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 に答える