You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Plainecassagne, Marie Josephe" <mp...@ptc.com> on 2006/02/24 14:59:05 UTC
HTTP CLIENT - Question regarding charset setting in MultipartPostMethod
Hello,
I am working for Parametric Technology in France. Parametric Technology
provides a WEB - Based application : Windchill-PDMLink. This suite is a
PDM application.
For our customer, Thales, I am developing a proof of concept regarding
the integration of PDMLink with Cadence (CAD application). In this
context, I am using :
- SOAP to communicate with PDMLink (queries, document creation)
- HTTPClient to upload files to this server.
The servlet I am talking to with HTTPClient has a bug when it parses a
multipart header. It expects the header to contain something like :
charset="ISO-8859-1" while HTTPClient sends charset=ISO-8859-1 (no
double quotes). I can fix this bug by myself on the servlet but it is
servlet that is provided by the standard tool and, for a customer, I
cannot provide this "local" patch.
I have 2 solutions that would work with this servlet :
- remove the charset setting in the header
- change the charset setting to ="ISO-8859-1"
I don't know how I can make it. Can you help me?
I have tested versions 2 and versions 3 of HTTPClient. Both of them send
the same header : application/octet-stream; charset=ISO-8859-1
Thanks for your help.
Best regards
Marie-Jo Plainecassagne
PS My code wirh HTTPClient 2.0.2 :
File targetFile;
String szURL;
...
URL targetURL = new URL(szURL);
MultipartPostMethod filePost = new MultipartPostMethod();
filePost.setPath(targetURL.getPath());
filePost.addParameter(
targetFile.getName(),
targetFile);
HttpClient client = new HttpClient();
client.getState().setCredentials(
null,
targetURL.getHost(),
new
UsernamePasswordCredentials(atdmConnection.getUser(),
atdmConnection.getPassword())
);
client.startSession(targetURL);
int status = client.executeMethod(filePost);
if (status != 200) {
System.out.println(status + "\n" +
filePost.getResponseBodyAsString());
throw new Exception("Unable to upload file. Error = " +
filePost.getResponseBodyAsString());
}
Re: HTTP CLIENT - Question regarding charset setting in MultipartPostMethod
Posted by Michael Becke <mb...@gmail.com>.
Hi Marie-Jo,
Sounds like you're referring to the multipart headers, is that
correct? Assuming so, you can can control the chartset parameter by
using the FilePart object directly. For example try:
FilePart f = new FilePart(targetFile.getName(), targetFile);
f.setChartSet(null); // remove the header
or
f.setCharSet("\"ISO-8859-1\""); // change the header to "ISO-8859-1"
filePost.addPart(f);
Also, if you're going to use HttpClient 3.0 I would recommend moving
away from the MultipartPostMethod and using the PostMethod with the
MultipartRequestEntity instead.
Mike
On 2/24/06, Plainecassagne, Marie Josephe <mp...@ptc.com> wrote:
> I have 2 solutions that would work with this servlet :
> - remove the charset setting in the header
> - change the charset setting to ="ISO-8859-1"
> I don't know how I can make it. Can you help me?
>
> I have tested versions 2 and versions 3 of HTTPClient. Both of them send
> the same header : application/octet-stream; charset=ISO-8859-1
>
> Thanks for your help.
>
> Best regards
>
> Marie-Jo Plainecassagne
>
> PS My code wirh HTTPClient 2.0.2 :
>
> File targetFile;
> String szURL;
>
> ...
>
> URL targetURL = new URL(szURL);
> MultipartPostMethod filePost = new MultipartPostMethod();
> filePost.setPath(targetURL.getPath());
>
> filePost.addParameter(
> targetFile.getName(),
> targetFile);
>
> HttpClient client = new HttpClient();
> client.getState().setCredentials(
> null,
> targetURL.getHost(),
> new
> UsernamePasswordCredentials(atdmConnection.getUser(),
> atdmConnection.getPassword())
> );
> client.startSession(targetURL);
> int status = client.executeMethod(filePost);
>
> if (status != 200) {
> System.out.println(status + "\n" +
> filePost.getResponseBodyAsString());
> throw new Exception("Unable to upload file. Error = " +
> filePost.getResponseBodyAsString());
> }
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
Re: HTTP CLIENT - Question regarding charset setting in MultipartPostMethod
Posted by sebb <se...@gmail.com>.
Can you perhaps tell HttpClient that the charset is
"ISO-8859-1"
instead of
ISO-8859-1
Just a thought - might be worth a try.
S.
On 24/02/06, Plainecassagne, Marie Josephe <mp...@ptc.com> wrote:
> Hello,
>
> I am working for Parametric Technology in France. Parametric Technology
> provides a WEB - Based application : Windchill-PDMLink. This suite is a
> PDM application.
>
> For our customer, Thales, I am developing a proof of concept regarding
> the integration of PDMLink with Cadence (CAD application). In this
> context, I am using :
> - SOAP to communicate with PDMLink (queries, document creation)
> - HTTPClient to upload files to this server.
>
> The servlet I am talking to with HTTPClient has a bug when it parses a
> multipart header. It expects the header to contain something like :
> charset="ISO-8859-1" while HTTPClient sends charset=ISO-8859-1 (no
> double quotes). I can fix this bug by myself on the servlet but it is
> servlet that is provided by the standard tool and, for a customer, I
> cannot provide this "local" patch.
>
> I have 2 solutions that would work with this servlet :
> - remove the charset setting in the header
> - change the charset setting to ="ISO-8859-1"
> I don't know how I can make it. Can you help me?
>
> I have tested versions 2 and versions 3 of HTTPClient. Both of them send
> the same header : application/octet-stream; charset=ISO-8859-1
>
> Thanks for your help.
>
> Best regards
>
> Marie-Jo Plainecassagne
>
> PS My code wirh HTTPClient 2.0.2 :
>
> File targetFile;
> String szURL;
>
> ...
>
> URL targetURL = new URL(szURL);
> MultipartPostMethod filePost = new MultipartPostMethod();
> filePost.setPath(targetURL.getPath());
>
> filePost.addParameter(
> targetFile.getName(),
> targetFile);
>
> HttpClient client = new HttpClient();
> client.getState().setCredentials(
> null,
> targetURL.getHost(),
> new
> UsernamePasswordCredentials(atdmConnection.getUser(),
> atdmConnection.getPassword())
> );
> client.startSession(targetURL);
> int status = client.executeMethod(filePost);
>
> if (status != 200) {
> System.out.println(status + "\n" +
> filePost.getResponseBodyAsString());
> throw new Exception("Unable to upload file. Error = " +
> filePost.getResponseBodyAsString());
> }
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org