json - Http post request in Angular2 does not pass parameters -


i trying send parameter using angular2 post python/tornado back-end returns json object. parameters being sent @ python side, returning 400 post missing arguments error. using ionic 2/angular2 in front-end , python/tornado server.

angular2 code follows: here content variable containing html table

let body = json.stringify({content: content}); let headers = new headers({ 'content-type': 'application/json' }); let options = new requestoptions({ headers: headers }); this.http.post(url, body, options).map(res => res.json()).subscribe(data => {       console.log(data) }, error => {       console.log(json.stringify(error)); }); 

python code follows:

def post(self):     print self.request.arguments     print self.get_argument('content')     self.finish(dict(result="ok", data=content)) 

here error:

[w 160824 06:04:30 web:1493] 400 post /test (182.69.5.99): missing argument content [w 160824 06:04:30 web:1908] 400 post /test (182.69.5.99) 1.67ms 

your angular2 code looks reasonable, python code wrong, because treating request x-www-form-urlencoded. have access json string through request.body property:

data = tornado.escape.json_decode(self.request.body) 

see https://stackoverflow.com/a/28140966/2380400 answer similar question.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -