bug记录(1)

来源:互联网 发布:.net程序员面试宝典 编辑:程序博客网 时间:2024/06/07 06:49

第一个:

                在编写一个远程调用接口时,远程传过来的是一个PDF报表文件,PrintWrite打印出来。在用httpclient远程访问时,发现打印报表为空白。

public String postreport(String url, Map<String, String> params) {        String resp = null;        CloseableHttpClient httpclient = HttpClients.createDefault();        HttpPost httppost = new HttpPost(url);        List<NameValuePair> formparams = new ArrayList<NameValuePair>();        Set<String> keySet = params.keySet();        for (String key : keySet) {            formparams.add(new BasicNameValuePair(key, params.get(key)));        }        try {            UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(formparams, ApplicationConstant.UTF_8);            httppost.addHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");            httppost.setHeader("Accept", "application/json");            uefEntity.setContentType("text/json");            httppost.setEntity(uefEntity);            httppost.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 600000);            CloseableHttpResponse response = httpclient.execute(httppost);            HttpEntity entity = response.getEntity();            if (entity != null) {                //这里是问题所在。去掉后面的编码就能正常打印报表                <span style="color:#FF0000;">resp = EntityUtils.toString(entity, ApplicationConstant.UTF_8);</span>            }            response.close();        } catch (IOException e) {            LOGGER.error("HttpClientUtil.post(),{}", e);            resp = ApplicationConstant.FAIL_CODE;        } finally {            try {                httpclient.close();            } catch (IOException e) {                LOGGER.error("HttpClientUtil.post(),{}", e);                resp = ApplicationConstant.FAIL_CODE;            }        }        return resp;    }

第二个:

              请求远程Jasperreports报表接口时,每次调用发现接口运行了2次。研究发现这与浏览器下载机制有关。Google和火狐都会出现这种情况,而IE却不会。先这样,下次在具体补充。




0 0
原创粉丝点击