记下一个静态页面转换思路(FOR SEO)

2019-05-17 15:04:15  卢浮宫  版权声明:本文为站长原创文章,转载请写明出处


一、写在前面:为了SEO要作出调整,这里记一下简单思路及相关操作

    程序拦截到请求后,进行第二次请求,根据内容以文件流的形式写入到新文件中,然后指向这个文件。


二、大体代码如下:

    

    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);



更多精彩请关注guangmuhua.com


最新评论: