You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Spam Proof <sp...@yahoo.co.in> on 2004/09/13 14:13:53 UTC

Unable to use post with a site

Hi,
 
I am using httpclient to post some data to a website.
 
The actual url that I am trying to post to is http://www.amfiindia.com/navreport.asp
 
The asp page corresponding to the form is given below 
 
-------navreport.asp------begin--------
<form name="abc" method="post" action="navreport.asp">
     <select size="1" name="cmbmf">
            <option value="all">ALL</option>
            <option value=39>abc</option> 
...
 </select>
<input type="submit" value="View" name="abcv" onclick="location.replace('#123')">
-------navreport.asp------end----------
 
I use the following code:
 
String url = "http://www.amfiindia.com/navreport.asp";

HttpClient client = new HttpClient();

PostMethod method = new PostMethod( url );

method.addParameter( "cmbmf", "all" );



method.setFollowRedirects(true);

int statusCode = client.executeMethod( method );

if( statusCode != -1 ) {

String contents = method.getResponseBodyAsString();

method.releaseConnection();

System.out.println( contents );

}

Instead of the posted results, I am getting the page containing the form. Should I use a different url because of the  onclick="location.replace('#123')" in the submit button?


Yahoo! India Matrimony: Find your life partneronline.

Re: Unable to use post with a site

Posted by Oleg Kalnichevski <ol...@apache.org>.
This will do the trick

===================================
HttpClient agent = new HttpClient();
PostMethod httppost = new PostMethod(
    "http://www.amfiindia.com/navreport.asp");
httppost.setRequestBody(new NameValuePair[] {
  new NameValuePair("cmbmf", "36"),
  new NameValuePair("btnview", "View")});
try {
  agent.executeMethod(httppost);
  System.out.println(httppost.getStatusLine());
  System.out.println(httppost.getResponseBodyAsString());
} finally {
  httppost.releaseConnection();
}
====================================

where "cmbmf" is the mutual fund id

Hope this helps

Oleg


On Mon, 2004-09-13 at 14:13, Spam Proof wrote:
> Hi,
>  
> I am using httpclient to post some data to a website.
>  
> The actual url that I am trying to post to is http://www.amfiindia.com/navreport.asp
>  
> The asp page corresponding to the form is given below 
>  
> -------navreport.asp------begin--------
> <form name="abc" method="post" action="navreport.asp">
>      <select size="1" name="cmbmf">
>             <option value="all">ALL</option>
>             <option value=39>abc</option> 
> ...
>  </select>
> <input type="submit" value="View" name="abcv" onclick="location.replace('#123')">
> -------navreport.asp------end----------
>  
> I use the following code:
>  
> String url = "http://www.amfiindia.com/navreport.asp";
> 
> HttpClient client = new HttpClient();
> 
> PostMethod method = new PostMethod( url );
> 
> method.addParameter( "cmbmf", "all" );
> 
> 
> 
> method.setFollowRedirects(true);
> 
> int statusCode = client.executeMethod( method );
> 
> if( statusCode != -1 ) {
> 
> String contents = method.getResponseBodyAsString();
> 
> method.releaseConnection();
> 
> System.out.println( contents );
> 
> }
> 
> Instead of the posted results, I am getting the page containing the form. Should I use a different url because of the  onclick="location.replace('#123')" in the submit button?
> 
> 
> Yahoo! India Matrimony: Find your life partneronline.


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


Re: Unable to use post with a site

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

first, you should try to add the following:

method.addParameter("abcv", "View")

because a submit button also defines a parameter
when it is given a name.

Due to the onclick handler, there should be a POST
request as well as the modification of the location.
I can't tell whether the location change affects the
current page or the one returned by the POST. It
seems more reasonable if it affects the current
page. Either way, since the new URL starts with a
#, it probably only scrolls the page that is shown to
an anchor within the page. Maybe to move the
submit button out of view, for those impatient users
that would click on it again and again.

cheers,
  Roland





Spam Proof <sp...@yahoo.co.in> 
13.09.2004 14:13
Please respond to
"Commons HttpClient Project"


To
commons-httpclient-dev@jakarta.apache.org
cc

Subject
Unable to use post with a site






Hi,
 
I am using httpclient to post some data to a website.
 
The actual url that I am trying to post to is 
http://www.amfiindia.com/navreport.asp
 
The asp page corresponding to the form is given below 
 
-------navreport.asp------begin--------
<form name="abc" method="post" action="navreport.asp">
     <select size="1" name="cmbmf">
            <option value="all">ALL</option>
            <option value=39>abc</option> 
...
 </select>
<input type="submit" value="View" name="abcv" 
onclick="location.replace('#123')">
-------navreport.asp------end----------
 
I use the following code:
 
String url = "http://www.amfiindia.com/navreport.asp";

HttpClient client = new HttpClient();

PostMethod method = new PostMethod( url );

method.addParameter( "cmbmf", "all" );



method.setFollowRedirects(true);

int statusCode = client.executeMethod( method );

if( statusCode != -1 ) {

String contents = method.getResponseBodyAsString();

method.releaseConnection();

System.out.println( contents );

}

Instead of the posted results, I am getting the page containing the form. 
Should I use a different url because of the 
onclick="location.replace('#123')" in the submit button?


Yahoo! India Matrimony: Find your life partneronline.