Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python服务器同时公开xml和json rpc接口_Python_Xml Rpc_Rpc_Json Rpc - Fatal编程技术网

Python服务器同时公开xml和json rpc接口

Python服务器同时公开xml和json rpc接口,python,xml-rpc,rpc,json-rpc,Python,Xml Rpc,Rpc,Json Rpc,正如标题所说,有没有一种方法可以同时向JSON-RPC和XML-RPC接口公开函数?最好在一个端口上运行一台服务器来响应这两种类型的请求 谢谢 返回不同格式的一种常用方法是以某种方式在url中指定您想要的类型。最常见的是: http://example.com/some/page.<format> 难道你不能直接读取http内容类型标题,然后根据它返回相应的答案吗?我想知道是否有一个库支持这种开箱即用的功能。我看到的库只是注册函数并在指定端口上启动服务器,但它们依赖于特定的协议,然

正如标题所说,有没有一种方法可以同时向JSON-RPC和XML-RPC接口公开函数?最好在一个端口上运行一台服务器来响应这两种类型的请求


谢谢

返回不同格式的一种常用方法是以某种方式在url中指定您想要的类型。最常见的是:

http://example.com/some/page.<format>

难道你不能直接读取http内容类型标题,然后根据它返回相应的答案吗?我想知道是否有一个库支持这种开箱即用的功能。我看到的库只是注册函数并在指定端口上启动服务器,但它们依赖于特定的协议,然后,正如下面建议的那样,阅读内容类型头的请求,并使用序列化程序将答案转换为正确的格式。更好的做法是使用HTTP头内容类型来请求所需的格式
http://example.com/some/page?output=<format>
// somewhere at the end of the method handling the request
return Formater(format_param).format(response_object)