Hi all

New to this list and I am not sure if my mails are getting thru. Anyway,
got problem with posting a form and loggin in. The post goes thru and I get
a 302 back. The HttpClient should handle the redirect by default right? The
problem is that I am not getting logged in on the site until i make a new
call with a new HttpClient. Everyhing is in a servlet, and first call to the
servlet doesnt logg me in, but the next one does. My post form code:

As you can see i'm trying to manually redirect also but i doesnt make any
difference.

   HttpResponse response = null;
        HttpEntity entity = null;
        HttpPost httpost = new HttpPost(BASE_URL
+"/index.php?func=do_login");

        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("btn_login", button));
        nvps.add(new BasicNameValuePair("txt_login", user));
        nvps.add(new BasicNameValuePair("psw_password", pass));

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

        HttpContext context = new BasicHttpContext();
        response = httpClient.execute(httpost, context);
        entity = response.getEntity();
        if (entity != null) {
            entity.consumeContent();
        }
        HttpUriRequest request = (HttpUriRequest) context.getAttribute(
                ExecutionContext.HTTP_REQUEST);

        String uri = BASE_URL + request.getURI().toString();

        HttpGet redirect = new HttpGet(uri);
        httpClient.execute(redirect, context);

        return context;

thanks

Reply via email to