squeaky-pl / japronto

Screaming-fast Python 3.5+ HTTP toolkit integrated with pipelining HTTP server based on uvloop and picohttpparser.
MIT License
8.61k stars 581 forks source link

POST Params paring issue #94

Open ifightcode opened 6 years ago

ifightcode commented 6 years ago

I was trying to extract POST parameters from requests and failed. What I've tried

#In Router
app.router.add_route('/add', add, method='POST')
#In Function
# Add url to database
def add(request):
    #try:
        db = request.mongo
        url = request.match_dict['url']
        key = request.match_dict['key']

And I'm getting error

File "in.py", line 41, in add
    url = request.match_dict['url']
KeyError: 'url'

Any idea how to get things functional?

nishankmahore commented 6 years ago

Try This

def basic(request):
    test=request.query['name']
sahibzadafahad99 commented 6 years ago

Try this

def basic(request): test = request.form['name']

vadim-shadrin commented 6 years ago
def auth(request):
      post = app.getPost(request)
      print(post)

def getPost(req):
        list  = req.body.decode('utf-8').split('&')
        post = {}
        for item in list:
            p = item.split('=')
            post[p[0]]=p[1]
        return post

     result is : {'username': 'vadim', 'password': '123'}

I did it this way