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()));
          }
        }      

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

Reply via email to