How to obtain JSON value from Post in a web.py server app?

我与影子孤独终老i 提交于 2019-12-05 18:43:38

You have to parse the json:

#!/usr/bin/env python
import web
import json

urls = (
    '/hello/', 'index'
)

class index:
    def POST(self):
        # How to obtain the name key and then print the value?
        data = json.loads(web.data())
        value = data["name"]
        return "Hello " + value + "!"

if __name__ == '__main__':
    app = web.application(urls, globals())
    app.run()

Also, make sure you're url is http://localhost:8080/hello/ in your cURL request; you have http://localhost:8080/hello in your example, which throws an error.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!