首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用python通过HTTP接收XML文档

使用python通过HTTP接收XML文档
EN

Stack Overflow用户
提问于 2010-05-25 19:00:06
回答 2查看 1.8K关注 0票数 0

我想用python做一个非常简单的send服务器,能够通过HTTP接收XML文档,然后作为响应发送XML文档。

你有什么例子吗?

只是为了了解如何安排工作。

非常感谢!

更新:

我需要这样的东西:

客户端对xml文档执行post:< request >< name>plus< /name> < param>2< /param> < param>3< /param> < /request>‘

python服务器回答:< response> < result>OK< /result> < outcome>5< /outcome> < /response >

你有这类事情的例子吗??

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-05-25 19:12:24

您可以使用XMLRPC:

SimpleXMLRPCServer示例(摘自Python文档)

服务器代码:

代码语言:javascript
运行
复制
from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler

# Restrict to a particular path.
class RequestHandler(SimpleXMLRPCRequestHandler):
    rpc_paths = ('/RPC2',)

# Create server
server = SimpleXMLRPCServer(("localhost", 8000),
                            requestHandler=RequestHandler)
server.register_introspection_functions()

# Register pow() function; this will use the value of
# pow.__name__ as the name, which is just 'pow'.
server.register_function(pow)

# Register a function under a different name
def adder_function(x,y):
    return x + y
server.register_function(adder_function, 'add')

# Register an instance; all the methods of the instance are
# published as XML-RPC methods (in this case, just 'div').
class MyFuncs:
    def div(self, x, y):
        return x // y

server.register_instance(MyFuncs())

# Run the server's main loop
server.serve_forever()

下面的客户端代码将调用前面服务器提供的方法:

代码语言:javascript
运行
复制
import xmlrpclib

s = xmlrpclib.ServerProxy('http://localhost:8000')
print s.pow(2,3)  # Returns 2**3 = 8
print s.add(2,3)  # Returns 5
print s.div(5,2)  # Returns 5//2 = 2

# Print list of available methods
print s.system.listMethods()
票数 1
EN

Stack Overflow用户

发布于 2010-05-25 19:07:18

标准库示例:

  • http://fragments.turtlemeat.com/pythonwebserver.php

或者使用一些轻量级的web框架:

  • web.py
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2903952

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档