2019-05-17 15:04:15 卢浮宫 版权声明:本文为站长原创文章,转载请写明出处
程序拦截到请求后,进行第二次请求,根据内容以文件流的形式写入到新文件中,然后指向这个文件。
HttpClient httpClient = HttpUtil.getHttpClient(); HttpPost httpPost = new HttpPost("http://guangmuhua.com/guangmuhua/getArticleDetailById.do?articleId=181"); httpPost.setHeader("Content-Type","application/json;charset=utf-8"); //设置请求参数,解决中文乱码问题 StringEntity entity = new StringEntity("","utf-8"); entity.setContentEncoding("UTF-8"); entity.setContentType("application/json"); httpPost.setEntity(entity); HttpResponse response = httpClient.execute(httpPost); HttpEntity respEntity = response.getEntity(); // InputStream instreams = respEntity.getContent(); String content = EntityUtils.toString(respEntity,"UTF-8"); JSONArray jsonArray = JSON.parseArray(content); String title = content = JSON.parseObject(jsonArray.get(0).toString()).getString("title"); content = JSON.parseObject(jsonArray.get(0).toString()).getString("content").replace("\\r","").replace("\\t",""); System.out.println(content);