我在一些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