当我使用HttpPost将数据发送到Django的403 FORBIDDEN消息 [英] 403 FORBIDDEN message when I use HttpPost to send data to Django

查看:433
本文介绍了当我使用HttpPost将数据发送到Django的403 FORBIDDEN消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Android的数据发送到Django应用程序。我希望将数据存储在源码数据库中的表被称为mytable的。下面是Android code:

I am trying to send data from android to Django app. I want to store the data in a table in sqlite database called "mytable". Here is the android code:

    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());
}

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

The issue is resolved now. I only needed to have a return value

推荐答案

听起来像Django的跨站请求伪造框架,它在默认情况下prevents第三方POST请求。阅读Django的 CSRF文档了解详情。

Sounds like Django's Cross-Site Request Forgery framework, which by default prevents third-party POST requests. Read Django's CSRF docs for details.

这篇关于当我使用HttpPost将数据发送到Django的403 FORBIDDEN消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆