How to parse an Angular POST request in WebApp2

前端 未结 3 630
臣服心动
臣服心动 2021-02-09 02:06

How do I get data from my Angular POST request in Google App Engine WebApp2? self.request.body returns a string, and self.request.get(key) returns not

相关标签:
3条回答
  • 2021-02-09 02:36

    Judging from your first print, it seems that Angular is sending the data in JSON format. Webapp2 will not parse this data for you. For your particular request, you can do:

    import json
    d = json.loads(self.request.body)
    v = d.get(key)
    

    If you want to be able to access the POST data using self.request.POST.get(key), you probably need to submit the data as form data. See this SO answer for more information about that.

    0 讨论(0)
  • 2021-02-09 02:44

    You can try this:

     self.request.POST.get(key) # POST requests
     self.request.GET.get(key)  # GET requests
    
    0 讨论(0)
  • 2021-02-09 02:46

    I always use self.request.get and able to get the data from GET/POST method, maybe you send the data in different format that only accessible by self.request.body?

    0 讨论(0)
提交回复
热议问题