title: After sending HTTP request to server sometimes I get status 302 (redirect)
body: <p>I try to send <code>POST</code> request to some server with json parameters and I wait json response.</p>
  
  <p>From Android it works fine but from Linux I get status <code>302</code> redirect. I really don't know where is my problem.</p>
  
  <p>Here is command from linux:</p>
  
  <blockquote>
    <p>curl  -i -X POST   --data "id=105&amp;json={\"orderBy\":0\"maxResults\":50}"  "<a href="http://mysite.com/ctlClient/" rel="nofollow">http://mysite.com/ctlClient/</a>"</p>
  </blockquote>
  
  <p>And I get response:</p>
  
  <pre><code> HTTP/1.1 302 Found
   Date: Thu, 04 Jul 2013 12:22:06 GMT
   Server: Apache
   X-Powered-By: PHP/5.3.19
   Set-Cookie: PHPSESSID=dqblvijvttgsdrv2u5tn72p9d6; path=/
   Expires: Thu, 19 Nov 1981 08:52:00 GMT
   Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
   Pragma: no-cache
   location: http://mysite.com/fwf/online/
   Content-Length: 0
   Connection: close
   Content-Type: text/html
  </code></pre>
  
  <p>From Server <code>access log</code>:</p>
  
  <blockquote>
    <p>"POST /ctlClient/ HTTP/1.1" 302 - "-" "curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5"</p>
  </blockquote>
  
  <p><strong>Android:</strong></p>
  
  <pre><code>            String data = "{\"orderBy\":0\"maxResults\":50}";
          String WEFI_MAIL_URL = "http://mysite.com/ctlClient/";
  
  
          DefaultHttpClient httpclient = null;
          String out = null;
  
          try {
              httpclient = new DefaultHttpClient();
  
              HttpPost httpost = new HttpPost(WEFI_MAIL_URL);
  
              httpost.setHeader("User-Agent", "Apache-HttpClient/4.1 (java 1.5)");
  
              List &lt;NameValuePair&gt; nvps = new ArrayList &lt;NameValuePair&gt;();
              nvps.add(new BasicNameValuePair("id", "105"));
              nvps.add(new BasicNameValuePair("json", data));
  
              httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
  
              HttpResponse response = httpclient.execute(httpost);
              HttpEntity entity = response.getEntity();
  
              if (entity != null) {
                  InputStream is = entity.getContent();
                  InputStreamReader isr = new InputStreamReader(is);
                  BufferedReader br = new BufferedReader(isr);
                  String line = null;
                  while ( (line = br.readLine()) != null) {
                      out = line;
                  }
                  is.close();
  
                  if(isTimeOut == false){
                      _loadActual();
                  }
                  else{
                      return;
                  }   
              } else {
                  return;
              }
  
          } catch (Exception e) {             
          }
  
          if (httpclient != null) {
              httpclient.getConnectionManager().shutdown();
          }       
      }
  </code></pre>
  
  <p><code>access log</code> on Android response:</p>
  
  <pre><code> "POST /ctlClient/ HTTP/1.1" 302 - "-" "Apache-HttpClient/4.1 (java 1.5)"
   "GET /fwf/online/ HTTP/1.1" 200 13981 "-" "Apache-HttpClient/4.1 (java 1.5)"
  </code></pre>
  
  <p>We can see that on POST server redirects me to <code>/fwf/online/</code></p>
  
  <p>From Wireshark i get the same results from both methods:</p>
  
  <pre><code>POST /ctlClient/ HTTP/1.1
  User-Agent: Apache-HttpClient/4.1 (java 1.5)
  Content-Type: application/x-www-form-urlencoded
  Content-Length: 301
  Host: mysite.com
  Connection: Keep-Alive
  </code></pre>
  
  <p>Why it works from Android but not from Linux with CURL?</p>
  
  <p><strong>Can anybody help me or give me direction how can i solve it?</strong></p>
  
  <p>Thank you </p>