4

問題は次のとおりです。 httpclient
を使用して、ログインデータをサーバーに投稿します。

デスクトップでライブヘッダーを使用してFirefoxを使用している間、サーバーは私をurl2 witk 302にリダイレクトし、次に302でurl3にリダイレクトし、次に200 OKを取得します。アンドロイドでは、同じログインページと 200 OK が表示されました。

次に、自動リダイレクト処理を無効にすると、応答が返され、302リダイレクトが見られましたが、

" String location = response.getHeaders("Location")[0].toString();" から、Firefox のものではなく、同じログイン ページの URL が返されました。

それがなぜなのか、私にはわかりません。

コード:

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 ヘッダー:

ここに画像の説明を入力

私が得るものは: location= /login/

4

0 に答える 0