java.io.IOException: chunked stream ended unexpectedly

求是科技 发布于 09/18 15:47
阅读 161
收藏 0

采用http请求框架遇到如下问题

java.io.IOException: chunked stream ended unexpectedly
    at org.apache.commons.httpclient.ChunkedInputStream.getChunkSizeFromInputStream(ChunkedInputStream.java:252)
    at org.apache.commons.httpclient.ChunkedInputStream.nextChunk(ChunkedInputStream.java:221)
    at org.apache.commons.httpclient.ChunkedInputStream.read(ChunkedInputStream.java:176)
    at java.io.FilterInputStream.read(FilterInputStream.java:133)
    at org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputStream.java:108)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
    at java.io.FilterInputStream.read(FilterInputStream.java:107)

请求框架代码如下  

public static String postMember(String menber_url, String authorization, Map<String, String> map) {
    log.info("发送地址:" + menber_url);
    String result = "";
    org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient();
    PostMethod myPost = new PostMethod(menber_url);
    myPost.addRequestHeader("authorization", authorization);
    myPost.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8");
    myPost.setContentChunked(true);
    client.getParams().setSoTimeout(300 * 1000);
    myPost.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
    Set<String> set = map.keySet();
    Iterator iterator = set.iterator();
    while (iterator.hasNext()) {
        String key = (String) iterator.next();
        String value = map.get(key);
        log.info("发送参数key:"+key+";value:"+value);
        myPost.addParameter(key, value);
    }
    try {
        int statusCode = client.executeMethod(myPost);
        log.info("报文发送状态值:" + statusCode);
        if (statusCode == HttpStatus.SC_OK) {
            BufferedInputStream bis = new BufferedInputStream(myPost.getResponseBodyAsStream());
            byte[] bytes = new byte[8192];
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            int count = 0;
            while ((count = bis.read(bytes)) > 0) {
                bos.write(bytes, 0, count);
            }
            byte[] strByte = bos.toByteArray();
            result = new String(strByte, 0, strByte.length, "utf-8");
            bos.close();
            bis.close();
            log.info("返回结果:" + result);
        }
    }catch (Exception e){
        e.printStackTrace();
    }
    return result;
}

求助:请求报错:java.io.IOException: chunked stream ended unexpectedly

加载中
0
innerloop
innerloop
menber_url

张啥样 大约 我觉得大概率出现在这个url上 

返回顶部
顶部