You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Dan Alford <da...@appraisalforum.com> on 2003/09/24 23:59:38 UTC

Problem with multipart post data - Content-Transfer-Encoding: 8bit

Hi all,

I have a problem with a multipart post that I am doing to a third party
webserver. I am using a MultiPartPostMethod and adding parts to it by the
following :

 Hashtable params = transferObj.getPostParams();
    HttpMethod method;
    if (transferObj.isMultipartForm()) {
      method = new
MultipartPostMethod(transferObj.getTargetURL().toString());
      for (Enumeration e = params.elements(); e.hasMoreElements(); ) {
        Hashtable partParams = (Hashtable) e.nextElement();
        String field = (String) partParams.get("fieldName");
        if (partParams.containsKey("isFile")) {
          //file part
          byte[] data = ( (ByteArrayOutputStream)
partParams.get(CONTENT_VALUE)).
              toByteArray();
          String name = (String) partParams.get("fileName");

          String encoding = (String) partParams.get(CONTENT_ENC);
          ByteArrayPartSource part = new ByteArrayPartSource(name, data);
          FilePart filePart = new FilePart(field, part);
          ( (MultipartPostMethod) method).addPart(filePart);
        }
        else {
          //string part
          String data = (String) partParams.get(CONTENT_VALUE);
          System.out.println("setting "+field+"="+data);
          StringPart part = new StringPart(field,data);
           ( (MultipartPostMethod) method).addPart(part);

        }
      }

This correctly gets me my multipart request which I send to the server. The
problem is that the third party server doesnt seem to fully understand the
format of the post data.

It responds in xml with part of the encoding information still there, for
example:

 <TARGET="Content-Transfer-Encoding: 8bit AB-031717-01693-1"/>

when the data supplied as the field parameter above is "AB-031717-01693-1"
and the XML response should be

 <TARGET="AB-031717-01693-1"/>

I am using the latest rc ( httpclient 2.0-rc1).

I have two questions:
 Firstly, is this a bug or a problem with the target server?

secondly, if it is a problem with the target server, how can I disable the
output of the Content-Transfer-Encoding part of the multipart data?

Thanks in advance,

Dan Alford

---
[This E-mail scanned for viruses]


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org


Re: Problem with multipart post data - Content-Transfer-Encoding: 8bit

Posted by Dan Alford <da...@appraisalforum.com>.
Mike,

Thanks for the help. I am using the custom file and string parts and that
solved the problem. Let me know if you come up with a patch for this
problem.

Regards,
Dan Alford
----- Original Message ----- 
From: "Michael Becke" <be...@u.washington.edu>
To: "Commons HttpClient Project" <co...@jakarta.apache.org>
Sent: Wednesday, September 24, 2003 6:13 PM
Subject: Re: Problem with multipart post data - Content-Transfer-Encoding:
8bit


> Hi Dan,
>
> It seems that a number of servers do not handle multi-part requests
> correctly and subsequently have trouble with posts that include
> transfer-encoding or content-type.  Please see this email thread for a
> possible solution
> <http://marc.theaimsgroup.com/?t=105794025900005&r=1&w=2>.
>
> I will also start working on a patch that will make it easier to
> disable these headers without resorting to custom FileParts.
>
> Mike
>
> On Wednesday, September 24, 2003, at 05:59 PM, Dan Alford wrote:
>
> > Hi all,
> >
> > I have a problem with a multipart post that I am doing to a third party
> > webserver. I am using a MultiPartPostMethod and adding parts to it by
> > the
> > following :
> >
> >  Hashtable params = transferObj.getPostParams();
> >     HttpMethod method;
> >     if (transferObj.isMultipartForm()) {
> >       method = new
> > MultipartPostMethod(transferObj.getTargetURL().toString());
> >       for (Enumeration e = params.elements(); e.hasMoreElements(); ) {
> >         Hashtable partParams = (Hashtable) e.nextElement();
> >         String field = (String) partParams.get("fieldName");
> >         if (partParams.containsKey("isFile")) {
> >           //file part
> >           byte[] data = ( (ByteArrayOutputStream)
> > partParams.get(CONTENT_VALUE)).
> >               toByteArray();
> >           String name = (String) partParams.get("fileName");
> >
> >           String encoding = (String) partParams.get(CONTENT_ENC);
> >           ByteArrayPartSource part = new ByteArrayPartSource(name,
> > data);
> >           FilePart filePart = new FilePart(field, part);
> >           ( (MultipartPostMethod) method).addPart(filePart);
> >         }
> >         else {
> >           //string part
> >           String data = (String) partParams.get(CONTENT_VALUE);
> >           System.out.println("setting "+field+"="+data);
> >           StringPart part = new StringPart(field,data);
> >            ( (MultipartPostMethod) method).addPart(part);
> >
> >         }
> >       }
> >
> > This correctly gets me my multipart request which I send to the
> > server. The
> > problem is that the third party server doesnt seem to fully understand
> > the
> > format of the post data.
> >
> > It responds in xml with part of the encoding information still there,
> > for
> > example:
> >
> >  <TARGET="Content-Transfer-Encoding: 8bit AB-031717-01693-1"/>
> >
> > when the data supplied as the field parameter above is
> > "AB-031717-01693-1"
> > and the XML response should be
> >
> >  <TARGET="AB-031717-01693-1"/>
> >
> > I am using the latest rc ( httpclient 2.0-rc1).
> >
> > I have two questions:
> >  Firstly, is this a bug or a problem with the target server?
> >
> > secondly, if it is a problem with the target server, how can I disable
> > the
> > output of the Content-Transfer-Encoding part of the multipart data?
> >
> > Thanks in advance,
> >
> > Dan Alford
> >
> > ---
> > [This E-mail scanned for viruses]
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > commons-httpclient-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> > commons-httpclient-dev-help@jakarta.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
commons-httpclient-dev-help@jakarta.apache.org
>
> ---
> [This E-mail scanned for viruses]
>
>

---
[This E-mail scanned for viruses]


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org


Re: Problem with multipart post data - Content-Transfer-Encoding: 8bit

Posted by Michael Becke <be...@u.washington.edu>.
Hi Dan,

It seems that a number of servers do not handle multi-part requests 
correctly and subsequently have trouble with posts that include 
transfer-encoding or content-type.  Please see this email thread for a 
possible solution 
<http://marc.theaimsgroup.com/?t=105794025900005&r=1&w=2>.

I will also start working on a patch that will make it easier to 
disable these headers without resorting to custom FileParts.

Mike

On Wednesday, September 24, 2003, at 05:59 PM, Dan Alford wrote:

> Hi all,
>
> I have a problem with a multipart post that I am doing to a third party
> webserver. I am using a MultiPartPostMethod and adding parts to it by 
> the
> following :
>
>  Hashtable params = transferObj.getPostParams();
>     HttpMethod method;
>     if (transferObj.isMultipartForm()) {
>       method = new
> MultipartPostMethod(transferObj.getTargetURL().toString());
>       for (Enumeration e = params.elements(); e.hasMoreElements(); ) {
>         Hashtable partParams = (Hashtable) e.nextElement();
>         String field = (String) partParams.get("fieldName");
>         if (partParams.containsKey("isFile")) {
>           //file part
>           byte[] data = ( (ByteArrayOutputStream)
> partParams.get(CONTENT_VALUE)).
>               toByteArray();
>           String name = (String) partParams.get("fileName");
>
>           String encoding = (String) partParams.get(CONTENT_ENC);
>           ByteArrayPartSource part = new ByteArrayPartSource(name, 
> data);
>           FilePart filePart = new FilePart(field, part);
>           ( (MultipartPostMethod) method).addPart(filePart);
>         }
>         else {
>           //string part
>           String data = (String) partParams.get(CONTENT_VALUE);
>           System.out.println("setting "+field+"="+data);
>           StringPart part = new StringPart(field,data);
>            ( (MultipartPostMethod) method).addPart(part);
>
>         }
>       }
>
> This correctly gets me my multipart request which I send to the 
> server. The
> problem is that the third party server doesnt seem to fully understand 
> the
> format of the post data.
>
> It responds in xml with part of the encoding information still there, 
> for
> example:
>
>  <TARGET="Content-Transfer-Encoding: 8bit AB-031717-01693-1"/>
>
> when the data supplied as the field parameter above is 
> "AB-031717-01693-1"
> and the XML response should be
>
>  <TARGET="AB-031717-01693-1"/>
>
> I am using the latest rc ( httpclient 2.0-rc1).
>
> I have two questions:
>  Firstly, is this a bug or a problem with the target server?
>
> secondly, if it is a problem with the target server, how can I disable 
> the
> output of the Content-Transfer-Encoding part of the multipart data?
>
> Thanks in advance,
>
> Dan Alford
>
> ---
> [This E-mail scanned for viruses]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: 
> commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: 
> commons-httpclient-dev-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org