如何从Android向Djang发送数据

2024-10-03 23:26:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我找不到POST数据的问题,我在Heroku上部署了django应用程序,android应用程序需要在用户完成游戏后向其发送数据。当我测试不使用POST方法(硬编码值)保存数据时,它起作用了。有人能告诉我代码中的问题在哪里吗?在

在网址.py在

url(r'^scorepost/', 'scorepost'),

在视图.py在

^{pr2}$

安卓

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://testdjangoandroid.herokuapp.com/scorepost/");

try {
    List<NameValuePair> pairs = new ArrayList<NameValuePair>(5);
    pairs.add(new BasicNameValuePair("email", user_email));
    pairs.add(new BasicNameValuePair("difficulty", Integer.toString(difficulty)));
    pairs.add(new BasicNameValuePair("time", Long.toString(totalTime)));
    pairs.add(new BasicNameValuePair("moves", Integer.toString(totalMoves)));
    pairs.add(new BasicNameValuePair("score", Long.toString(totalScore)));

    httppost.setEntity(new UrlEncodedFormEntity(pairs));

    httpclient.execute(httppost);

Tags: 数据pyadd应用程序newemailpostpairs