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

15410年前 (2015-11-14)java技术12565

 

  /** 
     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();  
                }  
            }  
         }  

 

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

分享给朋友:

相关文章

 程序员的中秋礼物.......

程序员的中秋礼物.......

【小姐你好,我是程序员】“小姐你好,我是程序员。”女生礼貌地回答:“你好,程先生。”男:“……哦,叫我序员就可以了。”   【程序员的愿望】有一天一个程序员见到了上帝。上...

多说评论框怎么用更好

 1.隐藏屏蔽掉多说评论框的版权链接代码?简单css实现:多说隐藏版权链接,在后台自定义css添加:#ds-thread #ds-reset .ds-powered-by { display...

如何彻底卸载删除oracle数据库

 windows下如何彻底删除Oracle 软件环境: 1、Windows 2000+ORACLE 8.1.7 ,oracle 10g2、ORACLE安装路径为:C:\ORACLE实现方...

java.lang.ClassNotFoundException: oracle.jdbc.driver.OralceDriver

 java.lang.ClassNotFoundException: Oracle.jdbc.driver.OracleDriver这个错误;原因可能是 少了驱动 ,少包class...

freeMarker 截取字符串(操作字符串函数 )

<#if c.proSummary!?length gt 25>  <!-- 如果长度 >25 截取25个字-->    ...

jquery 操作html元素(及CSS)

jquery 操作html元素(及CSS)

 $("li").addClass("aui-user-view-cell aui-img") ;  //给元素添加样式$('#a1...

评论列表

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

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

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

支持下,非常不错。

发表评论

访客

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