Hi Oleg,

Thanks alot! Your example works perfect.
I guess that is why my java.net aproach usually worked - there i set the
parameters in the request body (but forgot to handle the HTTP/1.1 100
Continue this time).

Regards,


Jaap

-----Original Message-----
From: Oleg Kalnichevski [mailto:[EMAIL PROTECTED]
Sent: maandag 13 september 2004 1:11
To: Jakarta Commons Users List
Subject: Re: HttpClient cannot post Form like IE and Mozilla


Jaap,

This should do the trick
==========================================
// Create an instance of HttpClient.
HttpClient client = new HttpClient();

// Create a method instance.
PostMethod method = new PostMethod(
  "http://www.marinusjansen.nl/asp/search.asp";);

NameValuePair nvp[] = new NameValuePair[2];
nvp[0] = new NameValuePair();
nvp[0].setName("soortpand");
nvp[0].setValue("0");
nvp[1] = new NameValuePair();
nvp[1].setName("prijsklasse");
nvp[1].setValue("0");

method.setRequestBody(nvp);

try {
  client.executeMethod(method);
  System.out.println(method.getResponseBodyAsString());
} finally {
  // Release the connection.
  method.releaseConnection();
}
==========================================

(1) Do not deal directly with HTTP connections unless you really have
to. Let HttpClient take of connection management.

(2) Query parameters and request parameters are not exactly the same
thing. Apparently the server-side script can only handle parameters
passed within the request body

Cheers,

Oleg

On Sun, 2004-09-12 at 21:31, Jaap wrote:
> Hi,
>
> Sometimes I find a website that gives an unexpected response. Usually I
drop
> HttpClient for the basic java.net approach, but this time that did not
work
> too! Somehow HttpClient posts a form different than IE and Mozilla. How
> exactly i do not know - but maybe I am just doing something wrong in these
> particular cases.
>
> Below is an example of a website that works in IE/Mozilla, but it does not
> in HttpClient
>
> Copy paste this simple HTML to a local html file and execute it:
>
> <html><body>
> <form action="http://www.marinusjansen.nl/asp/search.asp"; method="post">
> <input name="soortpand" value="0"/><input name="prijsklasse"
> value="0"><input value="Search" type="submit">
> </form></body></html>
>
> You will see a list of houses will be returned by the
(www.marinusjansen.nl)
> webserver.
> - if you change post into get - no results are returned (actually most
> webservers don't care about that).
> - cookies and referer are of no influence to this webserver's behaviour (i
> tried that already).
>
> If you run HttpClient on this - the webserver will return something
> completely different.
> Try this in you favorite IDE
>
> HttpConnection httpCon = new HttpConnection("www.marinusjansen.nl", 80);
> HttpMethodBase http = new PostMethod();
> NameValuePair nvp[] = new NameValuePair[2];
> nvp[0] = new NameValuePair();
> nvp[0].setName("soortpand");
> nvp[0].setValue("0");
> nvp[1] = new NameValuePair();
> nvp[1].setName("prijsklasse");
> nvp[1].setValue("0");
> http.setQueryString(nvp);
> http.setPath("/asp/search.asp");
> HttpState state = new HttpState();
> http.execute(state, httpCon);
> System.out.print(http.getResponseBodyAsString());
>
> Has anybody a suggestion how i can get this to work?
>
> (For those who have trouble reading Dutch... The expected response is a
list
> of properties, but with HttpClient the response is: 'Cannot find any
> listings').
>
> Regards,
>
>
> Jaap
> ___________________________________
>
> jaap - yawi
> amsterdam science park
> kruislaan 402
> 1098 sm amsterdam
> the netherlands
> m: +31 6 4540 2828
> t: +31 20 888 4836
> f: +31 20 888 4838
> [EMAIL PROTECTED]
> http://jaap.nl
> http://yawi.nl
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to