You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by gu...@ibs.se on 2002/08/09 10:57:27 UTC

HTTPClient - PostMethod.setRequstBody(File) requires boundaries?

Hi,

I'm having trouble with posting files - I want to mimic the <form> <input 
type="file"> </form> of html. 

The example PostXML seemed very promising and works for basic uploads, 
however, it doesn't use additional parameters. I need to pass the file + a 
couple of parameters. However, when the body is set, it's set. There is no 
support for calling setRequestBody and the add.... This only yields 
IllegalStateExceptions since the body is already generated.

Does this mean that I need to generate the whole request body with 
boundaries and everything? Seems  a little to low level for my taste...

Thanks for your time.
/G 

Gunnar Ahlberg

IBS R&D AB                    Telephone: 08-627 45 01
Box 1350                               Fax: 08-627 23 78
Hemvarnsgatan 8              E-mail: gunnar.ahlberg@ibs.se
171 26 Solna                        http://www.ibs.se
Sweden

Re: HTTPClient - PostMethod.setRequstBody(File) requires boundaries?

Posted by Jesper de Jong <je...@yahoo.com>.
Hello Gunnar,

If you want to upload a file and possibly other form
parameters, the body of the message should be in
"application/form-data" format. See RFC 1867
(Form-based File Upload in HTML), available at
http://www.ietf.org.

Jesper de Jong
jespdj@yahoo.com

--- Jeff Dever <js...@sympatico.ca> wrote:
> Post parameters are www-url encoded and sent as the
> body.  Therefore, a
> request body and parameters are mutually exclusive. 
> Perhaps you are
> needing to send a file and a query string?   The
> query string is sent as
> part of the url and can be used with a response
> body.
> 
> setQueryString(String)
>     or
> setQueryString(NameValuePair[])
> 
> 
> gunnar.ahlberg@ibs.se wrote:
> 
> >
> > Hi,
> >
> > I'm having trouble with posting files - I want to
> mimic the <form>
> > <input type="file"> </form> of html.
> >
> > The example PostXML seemed very promising and
> works for basic uploads,
> > however, it doesn't use additional parameters. I
> need to pass the file
> > + a couple of parameters. However, when the body
> is set, it's set.
> > There is no support for calling setRequestBody and
> the add.... This
> > only yields IllegalStateExceptions since the body
> is already
> > generated.
> >
> > Does this mean that I need to generate the whole
> request body with
> > boundaries and everything? Seems  a little to low
> level for my
> > taste...
> >
> > Thanks for your time.
> > /G
> >
> > Gunnar Ahlberg
> >
> > IBS R&D AB                    Telephone: 08-627 45
> 01
> > Box 1350                               Fax: 08-627
> 23 78
> > Hemvarnsgatan 8              E-mail:
> gunnar.ahlberg@ibs.se
> > 171 26 Solna                       
> http://www.ibs.se
> > Sweden
> >
> >   
>
----------------------------------------------------------------
> > --
> > To unsubscribe, e-mail:   <
> > mailto:commons-dev-unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail: <
> > mailto:commons-dev-help@jakarta.apache.org>
> >
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: HTTPClient - PostMethod.setRequstBody(File) requires boundaries?

Posted by Jeff Dever <js...@sympatico.ca>.
Post parameters are www-url encoded and sent as the body.  Therefore, a
request body and parameters are mutually exclusive.  Perhaps you are
needing to send a file and a query string?   The query string is sent as
part of the url and can be used with a response body.

setQueryString(String)
    or
setQueryString(NameValuePair[])


gunnar.ahlberg@ibs.se wrote:

>
> Hi,
>
> I'm having trouble with posting files - I want to mimic the <form>
> <input type="file"> </form> of html.
>
> The example PostXML seemed very promising and works for basic uploads,
> however, it doesn't use additional parameters. I need to pass the file
> + a couple of parameters. However, when the body is set, it's set.
> There is no support for calling setRequestBody and the add.... This
> only yields IllegalStateExceptions since the body is already
> generated.
>
> Does this mean that I need to generate the whole request body with
> boundaries and everything? Seems  a little to low level for my
> taste...
>
> Thanks for your time.
> /G
>
> Gunnar Ahlberg
>
> IBS R&D AB                    Telephone: 08-627 45 01
> Box 1350                               Fax: 08-627 23 78
> Hemvarnsgatan 8              E-mail: gunnar.ahlberg@ibs.se
> 171 26 Solna                        http://www.ibs.se
> Sweden
>
>    ----------------------------------------------------------------
> --
> To unsubscribe, e-mail:   <
> mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <
> mailto:commons-dev-help@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>