You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Meghana <sy...@yahoo.com> on 2005/07/27 04:57:28 UTC

Post to a secure site

Hi,
   I am trying to do a post to a secure site. First I am trying to get to a page using get method and that page contains a form with at least 20 parameters. I am trying to post to that page. The status from that is 200 OK  but it displays the same page. Do you see any error in the following code. 
 
    String url = "https://secure.mysite.com/mydir?param=value";
    HttpClient client = new HttpClient();
    GetMethod method = new GetMethod(url);
PostMethod pMethod = new PostMethod("/path/mentioned/in/the/actionfield/of/the/form");
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
      new DefaultHttpMethodRetryHandler(3, false));
    try {
      int statusCode = client.executeMethod(method);
      if (statusCode != HttpStatus.SC_OK) {
        System.err.println("Method failed: " + method.getStatusLine());
      }
      byte[] responseBody = method.getResponseBody();
      URI postURI = new URI("https","secure.mysite.com","/","");
   client.getHostConfiguration().setHost(postURI);
      NameValuePair[] params = {
    new NameValuePair("Day", "27")
    // Lot of other parameters
      };
      pMethod.setRequestBody(params);
      client.executeMethod(pMethod);
      System.out.println(pMethod.getStatusLine().toString());
      String postResponse = pMethod.getResponseBodyAsString();
      
    }.....
    ....
Thanks
-M
.


		
---------------------------------
 Start your day with Yahoo! - make it your home page 
__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

RE: Post to a secure site

Posted by "Jaya Christina B." <bj...@mahindrabt.com>.
 
Meghana
You can refer
http://jakarta.apache.org/commons/httpclient/2.0/redirects.html for info on
redirects.


-Jaya

-----Original Message-----
From: Meghana [mailto:sy62k@yahoo.com] 
Sent: Thursday, July 28, 2005 6:04 AM
To: HttpClient User Discussion
Subject: Re: Post to a secure site

Roland and Jaya,
   Thanks for your responses. It turns out that the server that I was
posting to doesnt like scraping programs. So it was not giving the final
page that I wanted. Once I set the user agent as Mozilla Firefox, it started
working. Now I am facing a small issue.
Some times it gives the response properly and some other times it doesnt.
Instead of giving a 302 response it gives 200. Not sure whats wrong. Any
ideas are appreciated. 

Thanks
-M

--- Roland Weber <RO...@de.ibm.com> wrote:

> Hello Meghana,
> 
> System.out.flush() has nothing to do with it.
> Either you print the value of the variable you are interested in, or 
> you print the wrong variable.
> 
> Please use the wire log to check what is received:
>
http://jakarta.apache.org/commons/httpclient/logging.html
> 
> hope that helps,
>   Roland
> 
> 
> 
> 
> Meghana <sy...@yahoo.com>
> 27.07.2005 14:43
> Please respond to
> "HttpClient User Discussion"
> 
> 
> To
> HttpClient User Discussion
> <ht...@jakarta.apache.org>
> cc
> 
> Subject
> Re: Post to a secure site
> 
> 
> 
> 
> 
> 
> Roland,
>       Thanks for your response. So do I need to flush the some where 
> in order to get the correct value in the "postResponse"? I used 
> System.out.flush() in vain.
> It displays the same page. Not sure where I am erring.
> 
> Thanks for you help
> -M
> 
> --- Roland Weber <RO...@de.ibm.com> wrote:
> 
> > Hi Meghana,
> > 
> > on first glance, the code looks OK. You are aware that the document 
> > from the GET request is stored as a byte array in "responseBody", 
> > while the one from the POST request is stored as a string in 
> > "postResponse"?
> > Since you "display" the same page twice, have you checked that the 
> > display method actually tries to display "postResponse" rather than 
> > "responseBody"
> > on the second occasion? Last time something like this happened in my 
> > code, it was caused by some copy-and-paste bug in the debug output 
> > statements.
> > 
> > hope that helps,
> >   Roland
> > 
> > 
> > 
> > 
> > Meghana <sy...@yahoo.com>
> > 27.07.2005 04:57
> > Please respond to
> > "HttpClient User Discussion"
> > 
> > 
> > To
> > httpclient-user@jakarta.apache.org
> > cc
> > 
> > Subject
> > Post to a secure site
> > 
> > 
> > 
> > 
> > 
> > 
> > Hi,
> >    I am trying to do a post to a secure site.
> First
> > I am trying to get to
> > a page using get method and that page contains a form with at least 
> > 20 parameters. I am trying to post to that page. The status from 
> > that is 200 OK  but it displays the same page. Do you see any error 
> > in the following code.
> > 
> >     String url =
> > "https://secure.mysite.com/mydir?param=value";
> >     HttpClient client = new HttpClient();
> >     GetMethod method = new GetMethod(url); PostMethod pMethod = new
> >
>
PostMethod("/path/mentioned/in/the/actionfield/of/the/form");
> > 
> >
>
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
> >       new DefaultHttpMethodRetryHandler(3,
> false));
> >     try {
> >       int statusCode =
> client.executeMethod(method);
> >       if (statusCode != HttpStatus.SC_OK) {
> >         System.err.println("Method failed: " + 
> > method.getStatusLine());
> >       }
> >       byte[] responseBody =
> > method.getResponseBody();
> >       URI postURI = new
> > URI("https","secure.mysite.com","/","");
> >    client.getHostConfiguration().setHost(postURI);
> >       NameValuePair[] params = {
> >     new NameValuePair("Day", "27")
> >     // Lot of other parameters
> >       };
> >       pMethod.setRequestBody(params);
> >       client.executeMethod(pMethod);
> > 
> >
>
System.out.println(pMethod.getStatusLine().toString());
> >       String postResponse =
> > pMethod.getResponseBodyAsString();
> > 
> >     }.....
> >     ....
> > Thanks
> > -M
> > .
> > 
> > 
> > 
> > ---------------------------------
> >  Start your day with Yahoo! - make it your home
> page
> > 
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam protection around 
> > http://mail.yahoo.com
> > 
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > httpclient-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> > httpclient-user-help@jakarta.apache.org
> > 
> > 
> 
> 
> 
>  
> ____________________________________________________
> Start your day with Yahoo! - make it your home page 
> http://www.yahoo.com/r/hs 
>  
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> httpclient-user-help@jakarta.apache.org
> 
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> httpclient-user-help@jakarta.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


RE: Post to a secure site

Posted by "Jaya Christina B." <bj...@mahindrabt.com>.
 
Meghana
Shudnt 200 be the (correct) code u shud be looking for??
302 occurs when there is a redirection happening... U'd need to set
followRedirects to true if you want to follow the redirection
Something like:
method.setFollowRedirects(true);

But, for me this isnt working..
PostMethod postMethod=new PostMethod("my url");
postMethod.setFollowRedirects(true);
System.out.println(postMethod.getFollowRedirects());

This SOP is always returning false even when I am setting it true!!

But anyways, I hope this helps you!!

Regards,
Jaya.
 

-----Original Message-----
From: Meghana [mailto:sy62k@yahoo.com] 
Sent: Thursday, July 28, 2005 6:04 AM
To: HttpClient User Discussion
Subject: Re: Post to a secure site

Roland and Jaya,
   Thanks for your responses. It turns out that the server that I was
posting to doesnt like scraping programs. So it was not giving the final
page that I wanted. Once I set the user agent as Mozilla Firefox, it started
working. Now I am facing a small issue.
Some times it gives the response properly and some other times it doesnt.
Instead of giving a 302 response it gives 200. Not sure whats wrong. Any
ideas are appreciated. 

Thanks
-M

--- Roland Weber <RO...@de.ibm.com> wrote:

> Hello Meghana,
> 
> System.out.flush() has nothing to do with it.
> Either you print the value of the variable you are interested in, or 
> you print the wrong variable.
> 
> Please use the wire log to check what is received:
>
http://jakarta.apache.org/commons/httpclient/logging.html
> 
> hope that helps,
>   Roland
> 
> 
> 
> 
> Meghana <sy...@yahoo.com>
> 27.07.2005 14:43
> Please respond to
> "HttpClient User Discussion"
> 
> 
> To
> HttpClient User Discussion
> <ht...@jakarta.apache.org>
> cc
> 
> Subject
> Re: Post to a secure site
> 
> 
> 
> 
> 
> 
> Roland,
>       Thanks for your response. So do I need to flush the some where 
> in order to get the correct value in the "postResponse"? I used 
> System.out.flush() in vain.
> It displays the same page. Not sure where I am erring.
> 
> Thanks for you help
> -M
> 
> --- Roland Weber <RO...@de.ibm.com> wrote:
> 
> > Hi Meghana,
> > 
> > on first glance, the code looks OK. You are aware that the document 
> > from the GET request is stored as a byte array in "responseBody", 
> > while the one from the POST request is stored as a string in 
> > "postResponse"?
> > Since you "display" the same page twice, have you checked that the 
> > display method actually tries to display "postResponse" rather than 
> > "responseBody"
> > on the second occasion? Last time something like this happened in my 
> > code, it was caused by some copy-and-paste bug in the debug output 
> > statements.
> > 
> > hope that helps,
> >   Roland
> > 
> > 
> > 
> > 
> > Meghana <sy...@yahoo.com>
> > 27.07.2005 04:57
> > Please respond to
> > "HttpClient User Discussion"
> > 
> > 
> > To
> > httpclient-user@jakarta.apache.org
> > cc
> > 
> > Subject
> > Post to a secure site
> > 
> > 
> > 
> > 
> > 
> > 
> > Hi,
> >    I am trying to do a post to a secure site.
> First
> > I am trying to get to
> > a page using get method and that page contains a form with at least 
> > 20 parameters. I am trying to post to that page. The status from 
> > that is 200 OK  but it displays the same page. Do you see any error 
> > in the following code.
> > 
> >     String url =
> > "https://secure.mysite.com/mydir?param=value";
> >     HttpClient client = new HttpClient();
> >     GetMethod method = new GetMethod(url); PostMethod pMethod = new
> >
>
PostMethod("/path/mentioned/in/the/actionfield/of/the/form");
> > 
> >
>
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
> >       new DefaultHttpMethodRetryHandler(3,
> false));
> >     try {
> >       int statusCode =
> client.executeMethod(method);
> >       if (statusCode != HttpStatus.SC_OK) {
> >         System.err.println("Method failed: " + 
> > method.getStatusLine());
> >       }
> >       byte[] responseBody =
> > method.getResponseBody();
> >       URI postURI = new
> > URI("https","secure.mysite.com","/","");
> >    client.getHostConfiguration().setHost(postURI);
> >       NameValuePair[] params = {
> >     new NameValuePair("Day", "27")
> >     // Lot of other parameters
> >       };
> >       pMethod.setRequestBody(params);
> >       client.executeMethod(pMethod);
> > 
> >
>
System.out.println(pMethod.getStatusLine().toString());
> >       String postResponse =
> > pMethod.getResponseBodyAsString();
> > 
> >     }.....
> >     ....
> > Thanks
> > -M
> > .
> > 
> > 
> > 
> > ---------------------------------
> >  Start your day with Yahoo! - make it your home
> page
> > 
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam protection around 
> > http://mail.yahoo.com
> > 
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > httpclient-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> > httpclient-user-help@jakarta.apache.org
> > 
> > 
> 
> 
> 
>  
> ____________________________________________________
> Start your day with Yahoo! - make it your home page 
> http://www.yahoo.com/r/hs 
>  
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> httpclient-user-help@jakarta.apache.org
> 
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> httpclient-user-help@jakarta.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: Post to a secure site

Posted by Meghana <sy...@yahoo.com>.
Roland and Jaya,
   Thanks for your responses. It turns out that the
server that I was posting to doesnt like scraping
programs. So it was not giving the final page that I
wanted. Once I set the user agent as Mozilla Firefox,
it started working. Now I am facing a small issue.
Some times it gives the response properly and some
other times it doesnt. Instead of giving a 302
response it gives 200. Not sure whats wrong. Any ideas
are appreciated. 

Thanks
-M

--- Roland Weber <RO...@de.ibm.com> wrote:

> Hello Meghana,
> 
> System.out.flush() has nothing to do with it.
> Either you print the value of the variable you are
> interested in, or you print the wrong variable.
> 
> Please use the wire log to check what is received:
>
http://jakarta.apache.org/commons/httpclient/logging.html
> 
> hope that helps,
>   Roland
> 
> 
> 
> 
> Meghana <sy...@yahoo.com> 
> 27.07.2005 14:43
> Please respond to
> "HttpClient User Discussion"
> 
> 
> To
> HttpClient User Discussion
> <ht...@jakarta.apache.org>
> cc
> 
> Subject
> Re: Post to a secure site
> 
> 
> 
> 
> 
> 
> Roland,
>       Thanks for your response. So do I need to
> flush
> the some where in order to get the correct value in
> the "postResponse"? I used System.out.flush() in
> vain.
> It displays the same page. Not sure where I am
> erring.
> 
> Thanks for you help
> -M
> 
> --- Roland Weber <RO...@de.ibm.com> wrote:
> 
> > Hi Meghana,
> > 
> > on first glance, the code looks OK. You are aware
> > that the document from the GET request is stored
> > as a byte array in "responseBody", while the one
> > from the POST request is stored as a string in
> > "postResponse"?
> > Since you "display" the same page twice, have you
> > checked that the display method actually tries to
> > display "postResponse" rather than "responseBody"
> > on the second occasion? Last time something like
> > this happened in my code, it was caused by some
> > copy-and-paste bug in the debug output statements.
> > 
> > hope that helps,
> >   Roland
> > 
> > 
> > 
> > 
> > Meghana <sy...@yahoo.com> 
> > 27.07.2005 04:57
> > Please respond to
> > "HttpClient User Discussion"
> > 
> > 
> > To
> > httpclient-user@jakarta.apache.org
> > cc
> > 
> > Subject
> > Post to a secure site
> > 
> > 
> > 
> > 
> > 
> > 
> > Hi,
> >    I am trying to do a post to a secure site.
> First
> > I am trying to get to 
> > a page using get method and that page contains a
> > form with at least 20 
> > parameters. I am trying to post to that page. The
> > status from that is 200 
> > OK  but it displays the same page. Do you see any
> > error in the following 
> > code. 
> > 
> >     String url =
> > "https://secure.mysite.com/mydir?param=value";
> >     HttpClient client = new HttpClient();
> >     GetMethod method = new GetMethod(url);
> > PostMethod pMethod = new 
> >
>
PostMethod("/path/mentioned/in/the/actionfield/of/the/form");
> > 
> >
>
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
> >       new DefaultHttpMethodRetryHandler(3,
> false));
> >     try {
> >       int statusCode =
> client.executeMethod(method);
> >       if (statusCode != HttpStatus.SC_OK) {
> >         System.err.println("Method failed: " +
> > method.getStatusLine());
> >       }
> >       byte[] responseBody =
> > method.getResponseBody();
> >       URI postURI = new
> > URI("https","secure.mysite.com","/","");
> >    client.getHostConfiguration().setHost(postURI);
> >       NameValuePair[] params = {
> >     new NameValuePair("Day", "27")
> >     // Lot of other parameters
> >       };
> >       pMethod.setRequestBody(params);
> >       client.executeMethod(pMethod);
> > 
> >
>
System.out.println(pMethod.getStatusLine().toString());
> >       String postResponse =
> > pMethod.getResponseBodyAsString();
> > 
> >     }.....
> >     ....
> > Thanks
> > -M
> > .
> > 
> > 
> > 
> > ---------------------------------
> >  Start your day with Yahoo! - make it your home
> page
> > 
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam
> > protection around 
> > http://mail.yahoo.com 
> > 
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > httpclient-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> > httpclient-user-help@jakarta.apache.org
> > 
> > 
> 
> 
> 
>  
> ____________________________________________________
> Start your day with Yahoo! - make it your home page 
> http://www.yahoo.com/r/hs 
>  
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> httpclient-user-help@jakarta.apache.org
> 
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> httpclient-user-help@jakarta.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: Post to a secure site

Posted by Roland Weber <RO...@de.ibm.com>.
Hello Meghana,

System.out.flush() has nothing to do with it.
Either you print the value of the variable you are
interested in, or you print the wrong variable.

Please use the wire log to check what is received:
http://jakarta.apache.org/commons/httpclient/logging.html

hope that helps,
  Roland




Meghana <sy...@yahoo.com> 
27.07.2005 14:43
Please respond to
"HttpClient User Discussion"


To
HttpClient User Discussion <ht...@jakarta.apache.org>
cc

Subject
Re: Post to a secure site






Roland,
      Thanks for your response. So do I need to flush
the some where in order to get the correct value in
the "postResponse"? I used System.out.flush() in vain.
It displays the same page. Not sure where I am erring.

Thanks for you help
-M

--- Roland Weber <RO...@de.ibm.com> wrote:

> Hi Meghana,
> 
> on first glance, the code looks OK. You are aware
> that the document from the GET request is stored
> as a byte array in "responseBody", while the one
> from the POST request is stored as a string in
> "postResponse"?
> Since you "display" the same page twice, have you
> checked that the display method actually tries to
> display "postResponse" rather than "responseBody"
> on the second occasion? Last time something like
> this happened in my code, it was caused by some
> copy-and-paste bug in the debug output statements.
> 
> hope that helps,
>   Roland
> 
> 
> 
> 
> Meghana <sy...@yahoo.com> 
> 27.07.2005 04:57
> Please respond to
> "HttpClient User Discussion"
> 
> 
> To
> httpclient-user@jakarta.apache.org
> cc
> 
> Subject
> Post to a secure site
> 
> 
> 
> 
> 
> 
> Hi,
>    I am trying to do a post to a secure site. First
> I am trying to get to 
> a page using get method and that page contains a
> form with at least 20 
> parameters. I am trying to post to that page. The
> status from that is 200 
> OK  but it displays the same page. Do you see any
> error in the following 
> code. 
> 
>     String url =
> "https://secure.mysite.com/mydir?param=value";
>     HttpClient client = new HttpClient();
>     GetMethod method = new GetMethod(url);
> PostMethod pMethod = new 
>
PostMethod("/path/mentioned/in/the/actionfield/of/the/form");
> 
>
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
>       new DefaultHttpMethodRetryHandler(3, false));
>     try {
>       int statusCode = client.executeMethod(method);
>       if (statusCode != HttpStatus.SC_OK) {
>         System.err.println("Method failed: " +
> method.getStatusLine());
>       }
>       byte[] responseBody =
> method.getResponseBody();
>       URI postURI = new
> URI("https","secure.mysite.com","/","");
>    client.getHostConfiguration().setHost(postURI);
>       NameValuePair[] params = {
>     new NameValuePair("Day", "27")
>     // Lot of other parameters
>       };
>       pMethod.setRequestBody(params);
>       client.executeMethod(pMethod);
> 
>
System.out.println(pMethod.getStatusLine().toString());
>       String postResponse =
> pMethod.getResponseBodyAsString();
> 
>     }.....
>     ....
> Thanks
> -M
> .
> 
> 
> 
> ---------------------------------
>  Start your day with Yahoo! - make it your home page
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam
> protection around 
> http://mail.yahoo.com 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> httpclient-user-help@jakarta.apache.org
> 
> 



 
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


RE: Post to a secure site

Posted by "Jaya Christina B." <bj...@mahindrabt.com>.
Meghana
Are u sure u are printing the right variable??
What (I think :) ) Roland is suggesting is that it looks like you are not
printing the correct variable i.e. "postResponse"

Cheers
Jaya.
 

-----Original Message-----
From: Meghana [mailto:sy62k@yahoo.com] 
Sent: Wednesday, July 27, 2005 6:13 PM
To: HttpClient User Discussion
Subject: Re: Post to a secure site

Roland,
      Thanks for your response. So do I need to flush the some where in
order to get the correct value in the "postResponse"? I used
System.out.flush() in vain.
It displays the same page. Not sure where I am erring.

Thanks for you help
-M

--- Roland Weber <RO...@de.ibm.com> wrote:

> Hi Meghana,
> 
> on first glance, the code looks OK. You are aware that the document 
> from the GET request is stored as a byte array in "responseBody", 
> while the one from the POST request is stored as a string in 
> "postResponse"?
> Since you "display" the same page twice, have you checked that the 
> display method actually tries to display "postResponse" rather than 
> "responseBody"
> on the second occasion? Last time something like this happened in my 
> code, it was caused by some copy-and-paste bug in the debug output 
> statements.
> 
> hope that helps,
>   Roland
> 
> 
> 
> 
> Meghana <sy...@yahoo.com>
> 27.07.2005 04:57
> Please respond to
> "HttpClient User Discussion"
> 
> 
> To
> httpclient-user@jakarta.apache.org
> cc
> 
> Subject
> Post to a secure site
> 
> 
> 
> 
> 
> 
> Hi,
>    I am trying to do a post to a secure site. First I am trying to get 
> to a page using get method and that page contains a form with at least 
> 20 parameters. I am trying to post to that page. The status from that 
> is 200 OK  but it displays the same page. Do you see any error in the 
> following code.
>  
>     String url =
> "https://secure.mysite.com/mydir?param=value";
>     HttpClient client = new HttpClient();
>     GetMethod method = new GetMethod(url); PostMethod pMethod = new
>
PostMethod("/path/mentioned/in/the/actionfield/of/the/form");
>    
>
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
>       new DefaultHttpMethodRetryHandler(3, false));
>     try {
>       int statusCode = client.executeMethod(method);
>       if (statusCode != HttpStatus.SC_OK) {
>         System.err.println("Method failed: " + 
> method.getStatusLine());
>       }
>       byte[] responseBody =
> method.getResponseBody();
>       URI postURI = new
> URI("https","secure.mysite.com","/","");
>    client.getHostConfiguration().setHost(postURI);
>       NameValuePair[] params = {
>     new NameValuePair("Day", "27")
>     // Lot of other parameters
>       };
>       pMethod.setRequestBody(params);
>       client.executeMethod(pMethod);
>      
>
System.out.println(pMethod.getStatusLine().toString());
>       String postResponse =
> pMethod.getResponseBodyAsString();
>  
>     }.....
>     ....
> Thanks
> -M
> .
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: Post to a secure site

Posted by Meghana <sy...@yahoo.com>.
Roland,
      Thanks for your response. So do I need to flush
the some where in order to get the correct value in
the "postResponse"? I used System.out.flush() in vain.
It displays the same page. Not sure where I am erring.

Thanks for you help
-M

--- Roland Weber <RO...@de.ibm.com> wrote:

> Hi Meghana,
> 
> on first glance, the code looks OK. You are aware
> that the document from the GET request is stored
> as a byte array in "responseBody", while the one
> from the POST request is stored as a string in
> "postResponse"?
> Since you "display" the same page twice, have you
> checked that the display method actually tries to
> display "postResponse" rather than "responseBody"
> on the second occasion? Last time something like
> this happened in my code, it was caused by some
> copy-and-paste bug in the debug output statements.
> 
> hope that helps,
>   Roland
> 
> 
> 
> 
> Meghana <sy...@yahoo.com> 
> 27.07.2005 04:57
> Please respond to
> "HttpClient User Discussion"
> 
> 
> To
> httpclient-user@jakarta.apache.org
> cc
> 
> Subject
> Post to a secure site
> 
> 
> 
> 
> 
> 
> Hi,
>    I am trying to do a post to a secure site. First
> I am trying to get to 
> a page using get method and that page contains a
> form with at least 20 
> parameters. I am trying to post to that page. The
> status from that is 200 
> OK  but it displays the same page. Do you see any
> error in the following 
> code. 
>  
>     String url =
> "https://secure.mysite.com/mydir?param=value";
>     HttpClient client = new HttpClient();
>     GetMethod method = new GetMethod(url);
> PostMethod pMethod = new 
>
PostMethod("/path/mentioned/in/the/actionfield/of/the/form");
>    
>
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
>       new DefaultHttpMethodRetryHandler(3, false));
>     try {
>       int statusCode = client.executeMethod(method);
>       if (statusCode != HttpStatus.SC_OK) {
>         System.err.println("Method failed: " +
> method.getStatusLine());
>       }
>       byte[] responseBody =
> method.getResponseBody();
>       URI postURI = new
> URI("https","secure.mysite.com","/","");
>    client.getHostConfiguration().setHost(postURI);
>       NameValuePair[] params = {
>     new NameValuePair("Day", "27")
>     // Lot of other parameters
>       };
>       pMethod.setRequestBody(params);
>       client.executeMethod(pMethod);
>      
>
System.out.println(pMethod.getStatusLine().toString());
>       String postResponse =
> pMethod.getResponseBodyAsString();
>  
>     }.....
>     ....
> Thanks
> -M
> .
> 
> 
>  
> ---------------------------------
>  Start your day with Yahoo! - make it your home page
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam
> protection around 
> http://mail.yahoo.com 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> httpclient-user-help@jakarta.apache.org
> 
> 



		
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


RES: Wrong CookiePolicy, I guess

Posted by Marcelo Chryssovergis <ma...@iea.org.br>.
Replying my own question, I changed the cookie policy and the error is no
longer exists.

But I still cannot log in to the site, cant understand why..

It´s very hard to make a generic class to login to many sites, almost
impossible (if not impossible). Each site has a specific issue

Well, i´ll keep trying

Cya, thanks

Marcelo




-----Mensagem original-----
De: Marcelo Chryssovergis [mailto:marcelodc@iea.org.br] 
Enviada em: quarta-feira, 27 de julho de 2005 08:48
Para: 'HttpClient User Discussion'
Assunto: Wrong CookiePolicy, I guess

Hello friends,

I´m having a problem here, and I´m guessing this is related with the cookie
policy I´m adopting. 

After I send the login data, the site returned shows an error like:


Database error: Duplicate entry 'de1a5e181846a3f532559ce9ef802d4c' for key 1

insert into sessions.sessions_d (sid,data,vars) values
('de1a5e181846a3f532559ce9ef802d4c,
$Version=0',unix_timestamp(),'a%3A0%3A%7B%7D')


This information is extracted from the cookie, but I guess the site is
extracting wrong parts of the cookie, since the parameters do not correspond
to the fields of the database.

My question is:

How do I find out what is the correct cookie policy I have to use?

Thanks a lot!

Marcelo




---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org







---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Wrong CookiePolicy, I guess

Posted by Marcelo Chryssovergis <ma...@iea.org.br>.
Hello friends,

I´m having a problem here, and I´m guessing this is related with the cookie
policy I´m adopting. 

After I send the login data, the site returned shows an error like:


Database error: Duplicate entry 'de1a5e181846a3f532559ce9ef802d4c' for key 1

insert into sessions.sessions_d (sid,data,vars) values
('de1a5e181846a3f532559ce9ef802d4c,
$Version=0',unix_timestamp(),'a%3A0%3A%7B%7D')


This information is extracted from the cookie, but I guess the site is
extracting wrong parts of the cookie, since the parameters do not correspond
to the fields of the database.

My question is:

How do I find out what is the correct cookie policy I have to use?

Thanks a lot!

Marcelo




---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: Post to a secure site

Posted by Roland Weber <RO...@de.ibm.com>.
Hi Meghana,

on first glance, the code looks OK. You are aware
that the document from the GET request is stored
as a byte array in "responseBody", while the one
from the POST request is stored as a string in
"postResponse"?
Since you "display" the same page twice, have you
checked that the display method actually tries to
display "postResponse" rather than "responseBody"
on the second occasion? Last time something like
this happened in my code, it was caused by some
copy-and-paste bug in the debug output statements.

hope that helps,
  Roland




Meghana <sy...@yahoo.com> 
27.07.2005 04:57
Please respond to
"HttpClient User Discussion"


To
httpclient-user@jakarta.apache.org
cc

Subject
Post to a secure site






Hi,
   I am trying to do a post to a secure site. First I am trying to get to 
a page using get method and that page contains a form with at least 20 
parameters. I am trying to post to that page. The status from that is 200 
OK  but it displays the same page. Do you see any error in the following 
code. 
 
    String url = "https://secure.mysite.com/mydir?param=value";
    HttpClient client = new HttpClient();
    GetMethod method = new GetMethod(url);
PostMethod pMethod = new 
PostMethod("/path/mentioned/in/the/actionfield/of/the/form");
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
      new DefaultHttpMethodRetryHandler(3, false));
    try {
      int statusCode = client.executeMethod(method);
      if (statusCode != HttpStatus.SC_OK) {
        System.err.println("Method failed: " + method.getStatusLine());
      }
      byte[] responseBody = method.getResponseBody();
      URI postURI = new URI("https","secure.mysite.com","/","");
   client.getHostConfiguration().setHost(postURI);
      NameValuePair[] params = {
    new NameValuePair("Day", "27")
    // Lot of other parameters
      };
      pMethod.setRequestBody(params);
      client.executeMethod(pMethod);
      System.out.println(pMethod.getStatusLine().toString());
      String postResponse = pMethod.getResponseBodyAsString();
 
    }.....
    ....
Thanks
-M
.


 
---------------------------------
 Start your day with Yahoo! - make it your home page 
__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org