HTTPCLIENT MultipartEntity 上传中文乱码
2015-10-02 10:46
501 查看
在使用MultipartEntity混合上传,有文件和有文本字段的时候,文本字段会出现乱码,解决方法如下:
HttpPost post=new HttpPost(url);
//准备builder
MultipartEntityBuilder builder =MultipartEntityBuilder.create();
//首先创建一个contentType声明上传字段的数据类型和编码
ContentType strContent=ContentType.create("text/plain",Charset.forName("UTF-8"));
//放入字段名,字段值,以及contentType
builder.addTextBody(field.name, field.value,strContent);
//放入POST请求
post.setEntity(builder.build());
//发起请求
HttpResponse response = new DefaultHttpClient().execute(post);
HttpPost post=new HttpPost(url);
//准备builder
MultipartEntityBuilder builder =MultipartEntityBuilder.create();
//首先创建一个contentType声明上传字段的数据类型和编码
ContentType strContent=ContentType.create("text/plain",Charset.forName("UTF-8"));
//放入字段名,字段值,以及contentType
builder.addTextBody(field.name, field.value,strContent);
//放入POST请求
post.setEntity(builder.build());
//发起请求
HttpResponse response = new DefaultHttpClient().execute(post);
相关文章推荐
- 转自牛客网-计算机网络基础相关
- http://jinnianshilongnian.iteye.com/blog/2018936
- win8搜索不到wifi怎么办?windows8搜索不到无线网络解决方法图解
- 网络原理,以及对VMware Workstation虚拟网络VMnet0、VMnet1、VMnet8的图解
- http://blog.sina.com.cn/s/blog_641926f30100trj1.html popen/pclose解析
- 几个网络唤醒工具
- 黑马程序员——Java语言:网络编程
- 《深入理解Linux网络技术内幕》阅读笔记(九)
- 基于Heritrix的特定主题的网络爬虫配置与实现
- TCP Replay
- 从HTTP到JDBC完整访问路径日志实现思路
- Linux网络管理工具
- debian连接网络
- HDU 5468 Puzzled Elena (2015年上海赛区网络赛A题)
- [网络和多线程]9、单例模式
- linux网络管理
- TCP/IP详解卷1 读书笔记:第四章 ARP地址解析协议
- tcp报文格式udp报文格式详解
- CG写实数字插画绘画视频教程
- tcp服务的测试程序开源