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

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

 

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

 

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

分享给朋友:

相关文章

org.tigris.subversion.javahl.ClientException:Attempted to lock an already-lo

 svn更新或提交是报错:org.tigris.subversion.javahl.ClientException:Attempted to lock an already-locked d...

js/jquery 实现点击图片更换头像(图片)实例

    总之一句话, 可以先将 file类型 的input 隐藏 起来,通过 图片(头像)的onclick事件 来触发 file 的onclick事件。1.引入外部js:...

太阳的后裔 经典对白(羞羞哒)

太阳的后裔 经典对白(羞羞哒)

关于电视剧 ,小编常说早就戒了,但是好剧呢还是要追滴。太阳的后裔, 追剧追到12集了,开始都是宋仲基比较调皮:我很想问你一件事情。什么都不要问,你知道我要问什么。看你现在一脸都是很想嘲笑我的表情。哪有...

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)

支持下,非常不错。

发表评论

访客

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