Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 888
Alok Agarwal Avatar asked Dec 11 '25 08:12

Alok Agarwal


1 Answers

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/".

like image 153
Daniel Roseman Avatar answered Dec 12 '25 22:12

Daniel Roseman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!