Httpclient redirects android

The problem is as follows:
I use httpclient to send login data to the server.

When using firefox on my desktop with live headers, the server redirects me to url2 witk 302, then to url3 with 302, and then I get 200 ok. In android, I got the same login page and 200 OK.

Then I turned off automatic call forwarding processing, got a response and saw 302 redirection, BUT

" String location = response.getHeaders("Location")[0].toString(); " gave me the same URL of the login page, not the one from firefox.

I have no idea why this is.

the code:

 HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(uri[0]); HttpResponse response; String responseString = null; HttpParams params = httpclient.getParams(); HttpClientParams.setRedirecting(params, false); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); // Adding namvalue pairs here - adding correct i'm sure httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); response = httpclient.execute(httppost); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == HttpStatus.SC_OK){ ByteArrayOutputStream out = new ByteArrayOutputStream(); response.getEntity().writeTo(out); out.close(); responseString = out.toString(); } else{ if (statusLine.getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) { String location = response.getHeaders("Location")[0].toString(); } response.getEntity().getContent().close(); } 

Firefox Headers:

enter image description here

I get: location = / login /

+4
source share

Source: https://habr.com/ru/post/1496562/


All Articles