2
我想從android發送數據到Django應用程序。我想將數據存儲在一個名爲「mytable」的sqlite數據庫中的表中。這裏是Android代碼:403 FORBIDDEN消息當我使用HttpPost發送數據到Django
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());
}
現在問題已解決。我只需要返回值
沒有你的代碼應該生成一個403. Django日誌是什麼樣的? – 2010-11-28 01:06:22
嘿!你如何檢查Django日誌?錯誤可能是因爲我沒有從views.py中返回任何東西? – user522559 2010-11-28 01:43:25