get方式调用http接口 Header赋参数值

1549年前 (2015-11-14)java技术12381

 

  /** 
     195.     * 发送 get请求 
     196.     */  
         public static void get() {  
             CloseableHttpClient httpclient = HttpClients.createDefault();  
            try {  
                 // 创建httpget.    
                 HttpGet httpget = new HttpGet("http://211.156.193.140:8002/cotrackapi/api/track/mail/1104389559880");  
                 httpget.setHeader("authenticate", "sdgszzswsgp_xiangmu123456");
                 httpget.setHeader("version", "ems_track_cn_1.0");
                 httpget.setHeader("Accept-Charset", "ISO8859-1");   
                // System.out.println("executing request " + httpget.getURI());  
                 // 执行get请求.    
                 CloseableHttpResponse response = httpclient.execute(httpget);  
                 try {  
                     // 获取响应实体    
                  HttpEntity entity = response.getEntity();  
                   //  System.out.println("--------------------------------------");  
                     // 打印响应状态    
                    /// System.out.println(response.getStatusLine());  
                    if (entity != null) {  
                        // 打印响应内容长度    
                     //  System.out.println("Response content length: " + entity.getContentLength());  
                       // 打印响应内容    
                       String jsmc=EntityUtils.toString(entity);
                        System.out.println("Response content: " + jsmc);  
                        String jsmc1=new String(jsmc.getBytes("ISO-8859-1"),"GBK");
                        System.out.println("------------------------------------"+jsmc1); 
                        String jsmc2=new String(jsmc.getBytes("ISO-8859-1"),"utf-8");
                        System.out.println("------------------------------------"+jsmc2); 
//                        String jsmc1=new String(jsmc.getBytes("ISO-8859-1"),"GBK");
//                        System.out.println("------------------------------------"+jsmc1); 
                    }  
                   
                 } finally {  
                     response.close();  
                 }  
            } catch (ClientProtocolException e) {  
                e.printStackTrace();  
            } catch (ParseException e) {  
               e.printStackTrace();  
            } catch (IOException e) {  
                e.printStackTrace();  
            } finally {  
                // 关闭连接,释放资源    
                 try {  
                    httpclient.close();  
                 } catch (IOException e) {  
                     e.printStackTrace();  
                }  
            }  
         }  

 

本文原创,转载必追究版权。

分享给朋友:

相关文章

每次开机checking file system on d

 解决方案:点击左下角(开始)- (运行)输入(CMD)回车 - 进入CMD界面- 输入(d:)回车 - 输入(chkdsk /f)中间有空格。回车,出现提示按Y键,完成后,重启一次会检...

揭秘!如何用一句话找到你的一万微友

 玩微商一年半的时间了,现在的微商如火如荼,很多刚进入微商行业的伙伴都在烦恼一个问题,那就是粉丝、粉丝,我最近调查了身边30多个微友,有25个竟然都是好友问题,有的竟然给我说主动加了50多个...

使用Myeclipse 8.5开发基于JAX-WS的Web service实例

使用Myeclipse 8.5开发基于JAX-WS的Web service实例

 本文为Web service 开发入门篇,主要介绍在Myeclipse 8.5环境下开发Web service的服务程序和客户端程序的基本流程。 在Weblogic 11g...

freeMarker Jfinal 获取session里的值

问题:freeMaker session取值的常用格式都试过 session["xxx"],session.xxx 直接xxx 都取不出来?????解决:JFinal与Struts...

MyEclipse10.7注册码生成

注意经验里的工具可能不可用,请点击 生成注册码工具  下载。提取码:p1w4MyEclipse10.7注册码激活步骤:点击下面的链接http://jingyan.baidu.com/arti...

评论列表

点我收录您
9年前 (2015-11-16)

爆照呢?发点别的东西嘛,纯技术博客有点单调

萨瓦迪卡 回复:
谢谢您的建议[害羞],会加内容的[太开心]右上角 关于站长 有照片额
9年前 (2015-11-17)
就要来海淘网
就要来海淘网
8年前 (2016-10-11)

支持下,非常不错。

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。