先说解决方法:很简单,把get请求换成post请求即可解决。
在对公司项目优化时,使用了当前网络请求封装更好的Retrofit框架,对Retrofit封装替换原有网络框架测试时,用的都是get请求,发现当参数中的数据较少时即一条数据没有问题,一旦上传两条数据就报错,返回提示错误如下(服务器方根本没有收到请求):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<title>404 - �Ҳ����ļ���Ŀ¼��</title>
<style type="text/css">
<!--
body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}
fieldset{padding:0 15px 10px 15px;}
h1{font-size:2.4em;margin:0;color:#FFF;}
h2{font-size:1.7em;margin:0;color:#CC0000;}
h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;}
#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF;
background-color:#555555;}
#content{margin:0 0 0 2%;position:relative;}
.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}
-->
</style>
</head>
<body>
<div id="header"><h1>���������</h1></div>
<div id="content">
<div class="content-container"><fieldset>
<h2>404 - �Ҳ����ļ���Ŀ¼��</h2>
<h3>��Ҫ���ҵ���Դ�����ѱ�ɾ���Ѹ����ƻ�����ʱ�����á�</h3>
</fieldset></div>
</div>
</body>
</html>
而直接用浏览器拼接参数测试返回报错如下:

开始没想到是怎么回事,经同事提出换post请求怎么样,没想到一换post请求立马解决,最后上网查get请求有长度限制不能超过2048字节,一般情况下获取数据用get,上传数据用post,这样可尽量避免出现这种问题,当然都用post也可以,我就是这样用的,哈哈。
829

被折叠的 条评论
为什么被折叠?



