hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henry Wijono" <hwij...@gmail.com>
Subject Re: Cookie and Post Issue..
Date Thu, 22 Jun 2006 06:26:52 GMT
Hi Roland,

Let me see if this makes sense.. :) I modified the code to do posting twice
and i am still getting "Your browser is not accepting the login cookie.
Please enable cookies in your browser".

What i am trying to do, there is a php on the front end and the application
connect to servlets. The httpclient will be getting the username, password
information from php and seamlessly run the job and execute java without
having the user to login twice.
The cookie I am seeing is none. So, the link to the site couldn't see
cookie.

Thank you for your inputs.

in PHP code
<script language="javascript">
function submitform()
{
    document.frmdologin.submit();
}
</script>
</head>
<body onload="submitform();"><center><b><?php echo $l_Logging_In;
?></b></center>
   <form name="frmdologin" method="post" action="<?php echo
$web_rootdir."/".$_POST["section"].$firstpage; ?>">
      <input type="hidden" name="message" value="<?php echo $message; ?>">
   </form>
</body>

httpClient.getParams().setBooleanParameter(
HttpMethodParams.SINGLE_COOKIE_HEADER, true);
                GetMethod getMethod = new GetMethod(urlA);
                try{
                    NameValuePair[] putData = {
                    new NameValuePair("username", username),
                    new NameValuePair("password", password),
                    new NameValuePair("loginid", username),
                    new NameValuePair("section", "inventory"),
                    new NameValuePair("Content-Length", "1500"),
                    new NameValuePair("Referer", urlA),
                    new NameValuePair("action", urlA),
                    //new NameValuePair("location", urlA),
                    new NameValuePair("method", "post"),
                    new NameValuePair("swpcookie", "ABC"),
                    new NameValuePair("Content-Type",
"application/x-www-form-urlencoded; charset=UTF8"),
                    new NameValuePair("Content-Style-Type", "text/css"),
                    new NameValuePair("User-Agent", "Mozilla/5.0 (Windows;
U; Windows NT 5.1; en-US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4" ),
                    new NameValuePair("Cache-Control", "private"),
                    new NameValuePair("pragma", "no-cache"),
                    new NameValuePair("Connection", "keep-alive")
                };
                    // Sending information
                    getMethod.setQueryString(putData);
                    httpClient.executeMethod(getMethod);

                    //write out the response body
                    System.out.println(" FIRST REPORT ");
                    is = new InputStreamReader(
getMethod.getResponseBodyAsStream());
                    in = new BufferedReader(is);

                    for ( String s; ( s = in.readLine() ) != null; )
                        System.out.println( s );

                } catch (HttpException he) {
                    System.err.println("Http error connecting to '" + urlC +
"'");
                    System.err.println(he.getMessage());
                    System.exit(-4);
                } catch (IOException ioe){
                    System.err.println("Unable to connect to '" + urlC +
"'");
                    System.exit(-3);
                }

                //clean up the connection resources
                getMethod.releaseConnection();

                try{
                    NameValuePair[] putData = {
                    new NameValuePair("username", username),
                    new NameValuePair("password", password),
                    new NameValuePair("loginid", username),
                    new NameValuePair("section", "inventory"),
                    new NameValuePair("Content-Length", "1500"),
                    new NameValuePair("Referer", urlA),
                    new NameValuePair("action", urlA),
                    //new NameValuePair("location", urlA),
                    new NameValuePair("message", "Your browser is not
accepting the login cookie.  Please enable cookies in your browser."),
                    new NameValuePair("method", "post"),
                    new NameValuePair("swpcookie", "ABC"),
                    new NameValuePair("Content-Type",
"application/x-www-form-urlencoded; charset=UTF8"),
                    new NameValuePair("Content-Style-Type", "text/css"),
                    new NameValuePair("User-Agent", "Mozilla/5.0 (Windows;
U; Windows NT 5.1; en-US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4" ),
                    new NameValuePair("Cache-Control", "private"),
                    new NameValuePair("pragma", "no-cache"),
                    new NameValuePair("Connection", "keep-alive")
                };

                GetMethod postMethod = new GetMethod(urlA);
                //postMethod.addParameters(putData);
                //postMethod.setRequestBody(putData);
                postMethod.setQueryString(putData);
                httpClient.executeMethod(postMethod);

                System.out.println(" SECOND REPORT ");
                is = new InputStreamReader(
postMethod.getResponseBodyAsStream());
                in = new BufferedReader(is);

                for ( String s; ( s = in.readLine() ) != null; )
                    out.println( s );

                // release any connection resources used by the method
                Cookie[] logoncookies =
httpClient.getState().getCookies(strURL,
m_port, "/", false);
                System.out.println("Logon cookies:");
                if (logoncookies.length == 0) {
                    System.out.println("None");
                } else {
                    for (int i = 0; i < logoncookies.length; i++) {
                        System.out.println("- " + logoncookies.toString());
                    }
                }

-- 
Regards,
Henry Wijono

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message