Question

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top