HttpClient 4 + HttpPost 有关文件名编码的帮助
我正在尝试将文件上传到 servlet。我正在尝试将文件名添加到标头并在 servlet 上读入...但是在 servlet 端,我可以获得的文件名(包含西里尔字母)只是 ??? ????.wmv。所以我的问题是如何正确上传具有 cirylic 文件名的文件?
我使用 HttpClient 4
the code snippet:
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.
PROTOCOL_VERSION,
HttpVersion.HTTP_1_1);
String url="testUrl";
httppost = new HttpPost(url);
httppost.addHeader(FILE_NAME_HEADER, file.getName());
任何有用的评论表示赞赏:)
Andrew
I am trying to upload file to servlet. I am trying to add file name to header and read in on servlet... But in the servlet side the file name (containing cyrillic) I can get is only ??? ?????.wmv. So my question is how to upload file with ciryllic file names correctly?
I use HttpClient 4
the code snippet:
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.
PROTOCOL_VERSION,
HttpVersion.HTTP_1_1);
String url="testUrl";
httppost = new HttpPost(url);
httppost.addHeader(FILE_NAME_HEADER, file.getName());
Any useful comment is appreciated :)
Andrew
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就我个人而言,我使用 Apache Commons FileUpload 库来处理文件上传。这是链接。您可以使用这个库,而不是自己做。如果它不能满足您的需求,您仍然可以研究自己的解决方案。
Personally I'm using Apache Commons FileUpload library to handle file uploads. Here is the link. Instead of doing Your own, you can use this library. If it doesn't satisfy your needs, you can still work on your own solution.
使用 HttpMultipartMode.BROWSER_COMPATIBLE 模式。
请参阅https://issues.apache.org/jira/browse/HTTPCLIENT-293 详情
Use HttpMultipartMode.BROWSER_COMPATIBLE mode.
See https://issues.apache.org/jira/browse/HTTPCLIENT-293 for the details