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:[EMAIL PROTECTED] 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 <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> > 27.07.2005 04:57 > Please respond to > "HttpClient User Discussion" > > > To > [email protected] > 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
