retrofit sendto failed: ECONNRESET (Connection reset by peer)【android客户端Post请求参数长度限制(参数过大)】解决办法
来源:互联网 发布:淘宝买枪的暗语 编辑:程序博客网 时间:2024/04/30 20:39
retrofit sendto failed: ECONNRESET (Connection reset by peer)【android客户端Post请求参数长度限制(参数过大)】解决办法
尊重原创,转载请注明出处,原文地址: http://blog.csdn.net/qq137722697
一、问题的出现
最近在做图文上传功能,使用retrofit作为上传工具,当文章数超过900字(中文)时会报sendto failed: ECONNRESET (Connection reset by peer)错误,stroke找了很多问题结果没几个人回答,回答的也不能解决问题;
二、解决过程
尝试一:后来就自己摸索,一开始是从参数长度入手,搜索了很多post请求上传是否有大小限制,其实http的post请求是没有参数大小限制的,只是浏览器和自己的服务器限制了(默认是2M),服务器限制的话只需要将tomcat的配置文件中加入maxPostSize=‘0’(无限制)。但是并没有解决问题,还是不能上传超长参数。
尝试二:后来想了一种捷径,post上传多张图片都没有限制,那我把参数封装成文件形式上传到服务器,让服务器读取文件里面的超长参数可以吧,一开始有这个想法就马上被否定了,因为这实在太l.o.w了。
三、最终解决办法
发现问题:原来,是我对Retrofit的@QueryMap() Map<String, String> params
不是很理解,使用@QueryMap()会直接放在post请求的data里面更url一起拼接,url请求有长度限制(浏览器、服务器等都有可能);
解决办法:既然找到原因了就好办了,参数和文件都用PartMap来构造:
接口类方法:
public interface ApiInterface { @Multipart @POST("saveVideo.action") Call<ResultBean> upload(@PartMap Map<String, RequestBody> params);}
Map初始化构造:
Map<String, RequestBody> paramsMap = new HashMap<>();
文件构造:
RequestBody fileBody = RequestBody.create(MediaType.parse("application/octet-stream"), file);paramsMap.put(file.getName() + "\";filename=\"" + file.getName(), fileBody);
参数构造:
fileMap.put("title", RequestBody.create(MediaType.parse("application/json"), title));fileMap.put("content", RequestBody.create(MediaType.parse("application/json"), content));
OK问题解决了。。。。
希望能帮到遇到相同问题的同胞们……
如文中有错误之处,望大家指出
如果我的文章解决了你的问题,欢迎点赞评论
2 0
- retrofit sendto failed: ECONNRESET (Connection reset by peer)【android客户端Post请求参数长度限制(参数过大)】解决办法
- Android客户端HTTP请求异常sendto failed: ECONNRESET (Connection reset by peer)解决方案
- socket failed:ECONNRESET(Connection reset by peer)
- Android网络请求报错:java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)
- 解决 java.net.SocketException: sendto failed: ECONNRESET (Connection reset by peer) 异常
- 解决:java.net.SocketException: sendto failed: ECONNRESET (Connection reset by peer)
- java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)我的解决办法
- libcore.io.ErrnoException: recvfrom failed: ECONNRESET (Connection reset by peer)
- java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)
- java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)
- *SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)
- Android通过Http协议POST请求异常(Connection reset by peer)
- 迷糊的IOException:Java.NET.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)
- 使用Mob短信验证出现 java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)异常
- Gem::RemoteFetcher::FetchError: Errno::ECONNRESET: Connection reset by peer - SSL_connect
- gem install 出现Errno::ECONNRESET: Connection reset by peer - SSL_connect
- gem Errno::ECONNRESET: Connection reset by peer - SSL_connect
- ZBX_TCP_READ() failed [Connection reset by peer]
- Maven实战研读(一)内存的修改
- 排序
- 感知机--模型与策略
- ROS中给turtlebot加两个传感器:kinect+hokuyo,进行gazebo仿真(一)
- request.getsession()和ActionContext.getContext().getSession()的区别
- retrofit sendto failed: ECONNRESET (Connection reset by peer)【android客户端Post请求参数长度限制(参数过大)】解决办法
- Android Studio怎么设置Tab键为4行缩进
- http及httpclient4.4简单介绍
- Struts2漏洞之__url中的\u0023代表#号,%20代表空格,\u003代表等于
- 顺序表(线性结构)
- 靶形数独
- POJ 1703
- 【JAVA之容器】1.集合框架体系
- 数据结构与算法复习笔记