On Wed, 2006-06-07 at 09:42 +0200, Stojce Dimski wrote:
> I am trying to execute plain vanilla login form with two text fields:
> 'firstname, lastname'...
> I am using jetty dump info servlet which echoes request content and
> enumerate all form parameters...
> 'HttpPost' doesn't contain any 'form parameters' handling as HttpClient3
> so I concluded that I have to use some kind of 'HttpEntity'... something
> like...
> 
> HttpPost request = new HttpPost("/test/dump/info");
> HttpEntity requestBody =
> StringEntity("firstname=cici+bella&lastname=ciccio+bello", "UTF-8");
> request.setEntity(requestBody);
> ...execute(request, connection);
> 
> I made various attempts but nothing worked... After that I made grep in
> the HttpCore4 for "application/x-www-form-urlencoded" string and there
> is nothing there... After that I made dummy FormEntity which set
> ContentType field and contains hard coded request params and everything
> worked...
> 
> Is there some support for this kind of requests in HttpCore4 and if not
> what are my alternatives ?

HttpCore is not the right place for this kind of functionality. It is
meant to be a low level transport library that provides the most generic
HTTP primitives only. Support for URL encoded forms will be made
available in HttpClient 4, which will be based on HttpCore.

You are very welcome to make the FormEntity class more generic, provide
some test cases for it and contribute it to HttpClient 4.0

Cheers,

Oleg


> Maybe I can contribute some code wit your assistance ?
> 
> plain text document attachment (FormEntity.java)
> import java.io.*;
> 
> import org.apache.http.entity.*;
> 
> public class FormEntity extends AbstractHttpEntity {
>     private String content = "firstname=cici+bella&lastname=ciccio+bello";
> 
>     public FormEntity () {
>         setContentType("application/x-www-form-urlencoded");
>     }
> 
>     public InputStream getContent () throws IOException, 
> IllegalStateException {
>         return new ByteArrayInputStream(content.getBytes());
>     }
> 
>     public long getContentLength () {
>         return content.length();
>     }
> 
>     public boolean isRepeatable () {
>         return true;
>     }
> 
>     public boolean isStreaming () {
>         return false;
>     }
> 
>     public void writeTo (OutputStream outstream) throws IOException {
>         outstream.write(content.getBytes());
>     }
> }
> 
> ---------------------------------------------------------------------
> 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