Hi,

I want to get the body from a page, which is redirected from a https adress.

I'm using Version 4.2.1 and Eclipse Java EE IDE for Web Developers Version: Indigo Service Release 2

I read the tutorials and this is my code:

    public final static void main(String[] args) throws Exception {

        HttpClient httpclient = new DefaultHttpClient();

        try {

            HttpPost httpost = new HttpPost("https://xxx.xx";);

            List <NameValuePair> nvps = new ArrayList <NameValuePair>();
            nvps.add(new BasicNameValuePair("login", "abc"));
            nvps.add(new BasicNameValuePair("password", "abc"));

httpost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));

            HttpResponse response = httpclient.execute(httpost);

            HttpEntity entity = response.getEntity();
System.out.println("Login form get: " + response.getStatusLine());
            EntityUtils.consume(entity);

        } finally {
            httpclient.getConnectionManager().shutdown();
        }
    }

It works, I get a "HTTP/1.1 302 Moved Temporarily", so I checked the HEADER for the redirectLocation.

            String redirectLocation = null;
            Header locationHeader = response.getFirstHeader("location");
            if (locationHeader != null) {
                redirectLocation = locationHeader.getValue();
            }

This works too, I got the new adress. My Problem is, I want to get the body of the redirected location (while I'm logged in).
So i tried:

            HttpGet httpget = new HttpGet(redirectLocation);
ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = httpclient.execute(httpget, responseHandler);
            System.out.println(responseBody);

But this is not the page, with the updated content i wanted. Furthermore I read, I have to set a "RedirectStrategy", so i tried
putting

((AbstractHttpClient) httpclient).setRedirectStrategy(new LaxRedirectStrategy());

after HttpClient httpclient = new DefaultHttpClient(); still no change.
(Anyway, why is httpclient.setRedirectStrategy(new LaxRedirectStrategy()); not working?)

So, my Question is, "How do i handle a 302 redirect an get the redirected body".

Thank you
Gerd Schmidt



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to