httpclient GET 得到的log, 以及如何解析出有用的不带加密的网站返回数据

使用HttpClient4.5.2进行GET请求时遇到加密数据问题,通过设置Header中的"Accept-Encoding"为"gzip,deflate"。目前尚未找到禁用加密传输的方法。关键步骤是使用EntityUtils.toString()将响应实体转换为字符串,避免获取类似"org.apache.http.client.entity.GzipDecompressingEntity@129a250c"的结果。示例代码展示了HttpGet请求的实现,但未能正确解析返回数据,需要进一步研究。" 104356863,7935884,IntelliJ IDEA高效快捷键指南,"['intellij idea', '开发工具', 'mac']
摘要由CSDN通过智能技术生成

使用HttpClient4.5.2去GET一个网站的数据,得到了一堆加密后的数据。得到了如何解析出有用的不带加密的网站返回数据?这个花了不少的时间搜索和研究。罗列如下:


设置Header里面的加密(httpget.addHeader("Accept-Encoding", "gzip,deflate");)。如何设置干脆成不加密传输,还没有解决,待进一步研究。


关键是使用EntityUtils.toString(entity3)来把entity给变成字符串才是对的。其他的方法,不能得出正确答案,只能得到一些类似: org.apache.http.client.entity.GzipDecompressingEntity@129a250c:的返回。


具体相关代码如下所示:


HttpGet httpget = new HttpGet("http://utilitytunnel.ewei.com/api/v1/engineers/16317/tickets.json?_count=0");
      


            httpget.addHeader("Content-Type", "application/json;charset=UTF-8");
            httpget.addHeader("Accept-Encoding", "gzip,deflate");
            httpget.setHeader("Accept", "application/json");  

            
            httpget.addHeader("_app_key", appKey);
            httpget.addHeader("_timestamp", timestampString);
            httpget.addHeader("_sign", sign);
            
//           httpget.addHeader("searchKey", "齐晓东");
           
           System.out.println("GET="+httpget.toString());
           
           Header headers[] = httpget.getAllHeaders();
           for (Header header:headers){
        	   System.out.println(header.getName()+"  "+header.getValue());
           }

    		
            CloseableHttpResponse response1 = httpclient.execute(httpget);  
            
            HttpEntity entity3 = response1.getEntity();
            
            System.out.println("----------------------------------------------get_respone1_ContentType="+entity3.getContentType());
            System.out.println("----------------------------------------------get_respone1_ContentLength="+entity3.getContentLength());
            System.out.println("VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVget_respone1_String="+EntityUtils.toString(entity3));


没能得到正确解析时的控制台log内容如下:


</pre></p><p></p><p>没能得到正确解析时的控制台log内容如下:</p><p><pre class="plain" name="code" snippet_file_name="blog_20160926_2_3861588" code_snippet_id="1902093">doView 里面 pointName检测点名称:null

timestampString=1474881335410


sign=a1fd47d6afb404251c1b5bea2ceeedc9
T_requesterString={"id":247502}
T_serviceDeskString={"id":1}
T_engineerString={"id":1}
17:15:35.417 [http-bio-8080-exec-90] DEBUG o.a.h.c.protocol.RequestAddCookies - CookieSpec selected: best-match
17:15:35.417 [http-bio-8080-exec-90] DEBUG o.a.h.c.protocol.RequestAuthCache - Auth cache not set in the context
17:15:35.417 [http-bio-8080-exec-90] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection request: [route: {}->http://utilitytunnel.ewei.com:80][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
17:15:35.417 [http-bio-8080-exec-90] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection leased: [id: 1][route: {}->http://utilitytunnel.ewei.com:80][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]
17:15:35.417 [http-bio-8080-exec-90] DEBUG o.a.h.impl.execchain.MainClientExec - Opening connection {}->http://utilitytunnel.ewei.com:80
17:15:35.422 [http-bio-8080-exec-90] DEBUG o.a.h.i.c.HttpClientConnectionOperator - Connecting to utilitytunnel.ewei.com/121.41.76.156:80
17:15:35.532 [http-bio-8080-exec-90] DEBUG o.a.h.i.c.HttpClientConnectionOperator - Connection established 192.168.43.216:62400<->121.41.76.156:80
17:15:35.533 [http-bio-8080-exec-90] DEBUG o.a.h.impl.execchain.MainClientExec - Executing request GET /api/v1/customers.json HTTP/1.1
17:15:35.533 [http-bio-8080-exec-90] DEBUG o.a.h.impl.execchain.MainClientExec - Target auth state: UNCHALLENGED
17:15:35.533 [http-bio-8080-exec-90] DEBUG o.a.h.impl.execchain.MainClientExec - Proxy auth state: UNCHALLENGED
17:15:35.533 [http-bio-8080-exec-90] DEBUG org.apache.http.headers - http-outgoing-1 >> G
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值