hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reudem...@free.fr
Subject Re: MultipartPostMethod adn UTF-8 parameter content.
Date Tue, 09 Nov 2004 10:59:39 GMT
I have followed your advice and use the org.apache.commons.codec.net.QCodec
package to encode the filename before sending the file. This code is :

QCodec qc = new QCodec();
mPost.addParameter("upload_file",qc.encode(f1.getName(),"UTF-8"),f1);

but it does not solve the problem as now the receiving server does NOT interpret
the encoding.
A dump of the wire shows :

DEBUG [org.apache.commons.httpclient.methods.MultipartPostMethod] enter
MultipartPostMethod.writeRequestBody(HttpState state, HttpConnection conn)
DEBUG [org.apache.commons.httpclient.HttpConnection] enter
HttpConnection.getRequestOutputStream()
DEBUG [org.apache.commons.httpclient.methods.multipart.Part] enter
sendParts(OutputStream out, Parts[])
DEBUG [org.apache.commons.httpclient.methods.multipart.Part] enter
send(OutputStream out)
DEBUG [org.apache.commons.httpclient.methods.multipart.Part] enter
sendStart(OutputStream out)
DEBUG [httpclient.wire] >> "--"
DEBUG [httpclient.wire] >> "----------------314159265358979323846"
DEBUG [httpclient.wire] >> "[\r][\n]"
DEBUG [org.apache.commons.httpclient.methods.multipart.FilePart] enter
sendDispositionHeader(OutputStream out)
DEBUG [org.apache.commons.httpclient.methods.multipart.Part] enter
sendDispositionHeader(OutputStream out)
DEBUG [httpclient.wire] >> "Content-Disposition: form-data; name="
DEBUG [httpclient.wire] >> """
DEBUG [httpclient.wire] >> "upload_file"
DEBUG [httpclient.wire] >> """
DEBUG [httpclient.wire] >> "; filename="
DEBUG [httpclient.wire] >> """
DEBUG [httpclient.wire] >>
"=?UTF-8?Q?note=C2=AF=C2=AFtraining=C2=AF24103-04.doc?="
DEBUG [httpclient.wire] >> """

Any idea ?



Quoting Guillaume Cottenceau <gc@mnc.ch>:

> reudeml04 'at' free.fr writes:
>
> > Hi All,
> >
> > I am using HTTPClient 3.0a2 and I am trying to mimic the POST of a form to
> > upload a binary file.
> > The code I use is below:
> >
> > MultipartPostMethod mPost = new MultipartPostMethod(addFileToPackageURL);
> > File f1 = new File(fa.getFilePath() + "\\" + fa.getFileName());
> > mPost.addParameter("upload_file",f1.getName(),f1);
> >
> > It works fine for all files BUT when the filename contains non basic ASCII
> chars
> > (like UTF-8), the received filename is transformed and unknow chars are
> changed
> > to question marks ?.
> >
> > It tried to add  mPost.addRequestHeader("Content-Type", "charset=\"UTF-8\""
> );
> > but it does not change anything.
> >
> > How should I proceed to allow the submit of a filename like
> > "note¯¯training¯abc.doc" so that it does not become
> > "note??training?abc.doc" on the other end of the wire ?
> >
> > Is this a bug or am I doing something wrong (likely :-)) ?
> >
> > Any help or suggestion would be much appreciated.
>
> It seems that javadoc explains that.
>
>
http://jakarta.apache.org/commons/httpclient/3.0/apidocs/org/apache/commons/httpclient/methods/MultipartPostMethod.html
>
> "Field names originally in non-ASCII character sets may be
> encoded using the method outlined in RFC 1522."
>
> --
> Guillaume Cottenceau
>



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


Mime
View raw message