Hello Alessandro,

Moving this discussion to the HttpClient Users list.

On 2/15/07, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:

hi there

i'm traing to send a multipart reqest using the InputStreamRequestEntity
in httpclient 3.0.1.
this is the code:

note: clientRequest is an incoming HttpServletRequest, and the stream
used for the InputStreamRequestEntity's constructor is obtained by using
the commons.FileUpload API.

        ServletFileUpload upload = new ServletFileUpload();
        FileItemIterator iter = upload.getItemIterator(clientRequest);
        while (iter.hasNext()) {
          FileItemStream item = iter.next();
          String name = item.getFieldName();
          if (item.isFormField()) {
            postMethod.addParameter(name,
Streams.asString(item.openStream()));
          } else {
            postMethod.setRequestEntity(new
InputStreamRequestEntity(item.openStream()));
          }
        }


Can you check if the 'item.openStream()' returns null? The reason the
exception is thrown is that the InputStream passed on to the
InputStreamRequestEntity is null.

upon executing the post method, the following exception is thrown:

java.lang.IllegalStateException: Content must be set before entity is
written
        at
org.apache.commons.httpclient.methods.InputStreamRequestEntity.writeRequ
est(InputStreamRequestEntity.java:176)
        at
org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequest
Body(EntityEnclosingMethod.java:495)
        at
org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase
.java:1973)
        at
org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java
:993)
        at
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMe
thodDirector.java:397)
        at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMetho
dDirector.java:170)
        at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:3
96)
        at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:3
24)

i'm obviously doing something wrong ;-) .. could someone help me
understand what?

thanks in advance for any hint!
cheers
alessandro


Regards,
Bindul

--
Bindul Bhowmik
MindTree Consulting Ltd.

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

Reply via email to