Alok Agarwal
Alok Agarwal

Reputation: 3099

Fetch data of Android POST in django server

I am trying to send POST request fro android to Django server and trying to execute the data

Android HTTP POST request

HttpClient httpclient = sslClient(new DefaultHttpClient());         
HttpPost post = new HttpPost("https://www.zzz.com/bulk-loc-add");       
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("bulkData", params[0]));
Log.v(TAG,"" + params[0]);
post.setEntity(new UrlEncodedFormEntity(pairs));                
HttpResponse response = httpclient.execute(post);

On my django Server i am writing

views.py

@csrf_exempt

def bulk_loc_add(request):

    print request.method
    bulk_data = request.POST
    print bulk_data
    Bulk =  request.GET
    print Bulk

request.method when i am printing its giving me GET rather than POST and when i am doing request.POST or request.GET its giving me blank QueryDict: {} i am not getting why it is blank i have seen my eclipse Logs data is there.

Upvotes: 3

Views: 1908

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599630

You are requesting a URL without an end slash, and Django is probably redirecting to the version with the slash, losing the POST data in the process. You should request "https://www.zzz.com/bulk-loc-add/".

Upvotes: 4

Related Questions