我正在尝试使用 sypne 构建一个 REST 应用程序。我想接收一个 JSON 文档(但不是使用称为对象名称的方法。我举个例子来澄清一下:我http://localhost/root
用以下内容对 URL 进行 POST:
{ "id": 1, "desc": "number" }
我有我的 spyne 应用程序:
class HelloWorldService(ServiceBase):
@rpc(_returns=AnyDict)
def root(ctx):
json_in=""
for data in ctx.in_string:
json_in = json_in + data
return json.loads(json_in)
application = Application([HelloWorldService],
tns='com.hello.webservices',
in_protocol=HttpRpc(validator='soft'),
out_protocol=JsonDocument()
)
而且我知道必须有更好的方法来做到这一点!提前感谢任何指向文档或解决方案的指针!
问候