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

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

 

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

 

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

分享给朋友:

相关文章

java解析JSON 数组数据 实例

 public  static void main (String args[]){  String sJson ="[{'acceptTim...

freemarker 判断日期变量为空处理 及InvalidReferenceException异常处理

at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:98);InvalidR...

MyEclipse 10安装svn

MyEclipse 10安装svn

 方法一:在线安装(推荐)1.打开HELP->MyEclipse ConfigurationCenter。切换到SoftWare标签页。 2.点击Add Site 打开对话框...

坑爹的ShowModalDialog 后台传值解决方案

 今天遇到需要ShowModalDialog打开页面,通过acceptanceIds 参数值后台过滤出相应结果前台  var url = "loadAccept...

MyEclipse 报错:'Building workspace' has encountered a problem解决方法

MyEclipse 报错:'Building workspace' has encountered a problem解决方法

          每次MyEclipse运行 工作空间报错如下:'Building workspac...

js/jquery 日历控件及实例下载

js/jquery 日历控件及实例下载

实现日历控件效果:页面:<link href="${base}/resource/${profile.path}/css/lhgcalendar.css" rel="...

评论列表

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

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

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

支持下,非常不错。

发表评论

访客

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