2 bxxo880917 bxxo880917 于 2016.02.01 16:43 提问

http请求的时候报“Bad chunk header”的错误

今天远程访问别的服务器的时候报了一个错误:Bad chunk header
就在EntityUtils.toString(response__input.getEntity())的时候
如果我加了一些限制条件,让他传过来的json数据少一点的话就没问题,数据多了就报这个错误,哪位大神帮我看一下:
代码如下:
public List getAllResultList() {
if (allResultList == null) {
User user = loginUser.getUser();
String mobile = user.getMobileNumber();

        List<AgentInfo> agentInfo = agentService.getAgentInfoByPhone(mobile);

        if (agentInfo.size() > 0) {
            try {
                String url_input = configService.getConfigValue(AGENT_INPUT_ACCOUNT_URL_ID);
                HttpGet get_input = null;

                JSONObject jsonObject = new JSONObject();   
                jsonObject.put("id", "");  
                jsonObject.put("bh", ""); 
                jsonObject.put("mno", "");
                jsonObject.put("mname", "");
                jsonObject.put("subno", "");   

                if (StringUtils.isNotBlank(agentInfo.get(0).getCode())) {
                    if (StringUtils.isNotBlank(agentInfo.get(0).getDepartmentId())) {
                        jsonObject.put("id", agentInfo.get(0).getDepartmentId());
                    }
                    jsonObject.put("bh", agentInfo.get(0).getCode());
                    if (StringUtils.isNotBlank(agentQuey)) {
                        if (StringUtils.isNumeric(agentQuey)) {
                            if (agentQuey.length()==15) {
                                jsonObject.put("mno", "'" + agentQuey + "'");
                            }else{
                                if (StringUtils.isNotBlank(agentQuey)) {
                                    //FIXME 商户号错误!
                                    return null;
                                }
                            }
                        }else{
                            jsonObject.put("mname", "'" + agentQuey + "'");
                        }
                    }
                }else{
                    if (StringUtils.isNotBlank(agentInfo.get(0).getDepartmentId())) {
                        jsonObject.put("id", agentInfo.get(0).getDepartmentId());
                    }
                    if (StringUtils.isNotBlank(salesCode)) {
                        jsonObject.put("bh", "'" + salesCode + "'");
                    }else{
                        if (StringUtils.isNotBlank(agentQuey)) {
                            if (StringUtils.isNumeric(agentQuey)) {
                                if (agentQuey.length()==15) {
                                    jsonObject.put("mno", "'" + agentQuey + "'");
                                }else{
                                    if (StringUtils.isNotBlank(agentQuey)) {
                                        //FIXME 商户号错误!
                                        return null;
                                    }
                                }
                            }else{
                                jsonObject.put("mname", "'" + agentQuey + "'");
                            }
                        }
                    }
                }

                get_input = new HttpGet(url_input+AGENT_INPUT_ACCOUNT_URL+"/"+java.net.URLEncoder.encode(jsonObject.toString(), "utf-8"));

                HttpClient client_input = HttpClientBuilder.create().build();
                HttpResponse response_input = client_input.execute(get_input);
                if(response_input.getStatusLine().getStatusCode() == 200){
                    String test = EntityUtils.toString(response_input.getEntity());
                    test = test.substring(test.indexOf("{"), test.length());
                    JSONObject object_input = JSONObject.fromObject(test);
                    System.out.println(object_input);
                    String code_input = object_input.getString("code");
                    if(Integer.parseInt(code_input) > 0){
                        FacesUtil.addErrorMessage(object_input.getString("msg"));
                        return null;
                    }else if(Integer.parseInt(code_input) == 0){
                        JSONArray jsonArray = (JSONArray) object_input.get("result");
                        List<Map<String,Object>> agentList = new ArrayList<Map<String,Object>>(jsonArray.size());

                        for (int m = 0; m < jsonArray.size(); m++){
                            String salesCode = ((JSONObject) jsonArray.get(m)).getString("ywyno");
                            String salesMan = ((JSONObject) jsonArray.get(m)).getString("ywtzr");

                            Map<String,Object> mapResult = new HashMap<String, Object>();
                            mapResult.put("salesCode", salesCode);
                            mapResult.put("salesMan", salesMan);
                            agentList.add(mapResult);
                        }

                        for (int i = 0; i < agentList.size(); i++)  //外循环是循环的次数
                        {
                            for (int j = agentList.size() - 1 ; j > i; j--)  //内循环是 外循环一次比较的次数
                            {

                                if (agentList.get(i).get("salesCode").equals(agentList.get(j).get("salesCode")))
                                {
                                    agentList.remove(j);
                                }

                            }
                        }
                        allResultList = agentList;
                        return allResultList;
                    }
                }else{
                    //FIXME 连接错误!
                    FacesUtil.addErrorMessage("对不起,连接错误,请稍后再试!");
                    return null;
                }
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }else{
            //FIXME 不是代理商跳转到申请商户页面
            FacesUtil.addErrorMessage("对不起,您不是代理商!");
            return null;
        }
        return null;
    }
    return allResultList;
}


报的错误是:
Hibernate: select this_.id as id47_0_, this_.code as code47_0_, this_.department_id as department3_47_0_, this_.name as name47_0_, this_.phone as phone47_0_ from agent_info this_ where this_.phone=?

org.apache.http.MalformedChunkCodingException: Bad chunk header
at org.apache.http.impl.io.ChunkedInputStream.getChunkSize(ChunkedInputStream.java:251)

at org.apache.http.impl.io.ChunkedInputStream.nextChunk(ChunkedInputStream.java:206)
at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:169)
at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:137)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.Reader.read(Reader.java:140)

at org.apache.http.util.EntityUtils.toString(EntityUtils.java:244)
at org.apache.http.util.EntityUtils.toString(EntityUtils.java:288)

2个回答

oyljerry
oyljerry   Ds   Rxr 2016.02.01 17:34

chunk就是http进行数据分片的方法,出错是不是你请求的数据太多,导致处理不正确

bxxo880917
bxxo880917 是的,就是请求的数据比较多才会报这个错,但是http请求传输的json数据块还有大小限制吗?如果数据比较多的话怎么办?
接近 2 年之前 回复
bxxo880917
bxxo880917   2016.02.17 09:14

没有人给小弟答个疑吗?

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!