Httpclient重定向android

Httpclient重定向android,android,httpclient,Android,Httpclient,问题如下: 我使用httpclient将登录数据发布到服务器。 在桌面上使用firefox时,服务器会将我重定向到url2 witk 302,然后再重定向到url3 witk 302,然后我得到200 ok。在安卓系统中,我得到了相同的登录页面和200 OK 然后我禁用了自动重定向处理,得到了响应并看到302重定向,但是 “String location=response.getHeaders(“location”)[0].toString();”为我提供了相同的登录页面url,而不是来自fir

问题如下:
我使用httpclient将登录数据发布到服务器。

在桌面上使用firefox时,服务器会将我重定向到url2 witk 302,然后再重定向到url3 witk 302,然后我得到200 ok。在安卓系统中,我得到了相同的登录页面和200 OK

然后我禁用了自动重定向处理,得到了响应并看到302重定向,但是

String location=response.getHeaders(“location”)[0].toString();
”为我提供了相同的登录页面url,而不是来自firefox的url

我不知道这是为什么

代码:

HttpClient-HttpClient=newdefaulthttpclient();
HttpPost HttpPost=新的HttpPost(uri[0]);
HttpResponse响应;
字符串responseString=null;
HttpParams params=httpclient.getParams();
HttpClientParams.setRedirecting(参数,false);
List nameValuePairs=新的ArrayList(2);
//在这里添加值对-我确信添加正确
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
response=httpclient.execute(httppost);
StatusLine StatusLine=response.getStatusLine();
如果(statusLine.getStatusCode()==HttpStatus.SC_OK){
ByteArrayOutputStream out=新建ByteArrayOutputStream();
response.getEntity().writeTo(out);
out.close();
responseString=out.toString();
}否则{
if(statusLine.getStatusCode()==HttpStatus.SC\u临时移动)
{
字符串位置=response.getHeaders(“位置”)[0].toString();
}
response.getEntity().getContent().close();
}      
Firefox标题:


我得到的是:location=/login/

您可以添加堆栈跟踪和代码。添加了一些代码,不知道堆栈跟踪,因为没有错误
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();     
}