2

我正在尝试将数据从 android 发送到 Django 应用程序。我想将数据存储在 sqlite 数据库中名为“mytable”的表中。这是安卓代码:

    try {
        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://localhost:8000/androidweb/edit/");
        JSONObject j = new JSONObject();
        try {
            j.put("name", "david");
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        nameValuePairs.add(new BasicNameValuePair("year", j.toString()));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    //  myTextView.setText(j.toString());
        HttpResponse response = httpclient.execute(httppost);
        myTextView.setText(response.getStatusLine().toString());
    //  myTextView.setText(response.toString());
    }catch(Exception e) {
        myTextView.setText("Error in http connection "+e.toString());
}

现在问题已经解决了。我只需要一个返回值

4

1 回答 1

2

听起来像 Django 的 Cross-Site Request Forgery 框架,默认情况下会阻止第三方 POST 请求。阅读 Django 的CSRF 文档了解详细信息。

于 2010-11-28T20:29:07.490 回答