我在一些json数据的主体中发送post请求,在服务器上进行处理,我希望以json数据的形式将结果返回给客户端(在手机上的C++应用程序),并且因此解析移动。 我有内部代码如下:Post print dictionary/json将错误返回给客户端
class ServerHandler(tornado.web.RequestHandler):
def post(self):
data = tornado.escape.json_decode(self.request.body)
id = data.get('id',None)
#process data from db (take a while) and pack in result which is dictinary
result = process_data(id)# returns dictionary from db= takes time
print 'END OF HANDLER'
print json.dumps(result)
#before this code below I have tried also
#return result
#return self.write(result)
#return self.write(json.dumps(result))
#return json.dumps(result)
self.set_header('Content-Type', 'application/json')
json_ = tornado.escape.json_encode(result)
self.write(json_)
self.finish()
#return json.dumps(result)
我总是印刷'END OF HANDLER'
及以下valid dictinary/json
在控制台上,但是当我在客户端移动阅读我总是得到
<html><title>405: Method Not Allowed</title><body>405: Method Not Allowed</body></html>
没有人有任何的想法是什么错误 ?
(我用CIwGameHttpRequest发送请求,并在文件是静态的它工作=> name.json但现在同样的内容在POST请求给错误。)
尝试使用CIwHTTP而不是CIwGameHttpRequest。如果它也不起作用,那么你正在调用错误的方法。 – noob 2013-03-26 20:45:36