从GZIPed分块响应获取实体内容

从GZIPed分块响应获取实体内容

本文介绍了Groovy HTTPBuilder:从GZIPed分块响应获取实体内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要向Web服务器发送POST请求,并能够读取由该服务器发送的响应。
我尝试使用HTTPBuilder库lib:

  def http = new HTTPBuilder('http:// myServer /')
http.setProxy(Proxy_IP,8080,http)
postBody = [cmd:'e',格式:'sep',c:'a',b:'b ',t:'u',r:'r',kl:'lop']

http.post(body:postBody,
requestContentType:URLENC){resp - >
HttpEntity he = resp.getEntity()
println$ {resp.getAllHeaders()}
println he.getContentType()
println$ {resp.getEntity() .getContent()}
}

执行此代码时发生异常:

  ERROR errors.GrailsExceptionResolver  - 处理请求时发生EOFException:[GET] / PROJECT / home / index 
意外结束的ZLIB输入流。 Stacktrace如下:
消息:ZLIB输入流的意外结束
Line |方法
- >> 240 |填入java.util.zip.InflaterInputStream
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 158 |请阅读''
| 116 |阅读。 。在java.util.zip.GZIPInputStream
|中138 |阅读org.apache.http.conn.EofSensorInputStream
| 184 |阅读。 。在java.io.InputStreamReader
|中140 |在java.io.Reader中读取

我将调试打开为Wire和Header,这就是我get:

  2012-01-06 16:50:12,219 [http-bio-8080-exec-2] DEBUG http.wire  - >> Accept:* / * [EOL]
2012-01-06 16:50:12,219 [http-bio-8080-exec-2] DEBUG http.wire - >> Content-Length:160 [EOL]
2012-01-06 16:50:12,219 [http-bio-8080-exec-2] DEBUG http.wire - >> 内容类型:应用程序/ x-www-form-urlencoded [EOL]
2012-01-06 16:50:12,219 [http-bio-8080-exec-2] DEBUG http.wire - >> Host:myServer [EOL]
2012-01-06 16:50:12,219 [http-bio-8080-exec-2] DEBUG http.wire - >> Proxy-Connection:Keep-Alive [EOL]
2012-01-06 16:50:12,219 [http-bio-8080-exec-2] DEBUG http.wire - >> Cookie:ASPSESSIONIDSSTTACTA = NFJKHEDRFGTKCGFEHGFKOANP [EOL]
2012-01-06 16:50:12,219 [http-bio-8080-exec-2] DEBUG http.wire->> Cookie2:$ Version = 1 [EOL]
2012-01-06 16:50:12,219 [http-bio-8080-exec-2] DEBUG http.wire - >> Accept-Encoding:gzip,deflate [EOL]
2012-01-06 16:50:12,219 [http-bio-8080-exec-2] DEBUG http.wire - >> [EOL]
2012-01-06 16:50:12,219 [http-bio-8080-exec-2] DEBUG http.headers - >> POST myUrl HTTP / 1.1
2012-01-06 16:50:12,219 [http-bio-8080-exec-2] DEBUG http.headers - >>接受:* / *
2012-01-06 16:50:12,219 [http-bio-8080-exec-2] DEBUG http.headers - >> Content-Length:160
2012-01-06 16:50:12,219 [http-bio-8080-exec-2] DEBUG http.headers - >>内容类型:application / x-www-form-urlencoded
2012-01-06 16:50:12,219 [http-bio-8080-exec-2] DEBUG http.headers - >>主机:myServer
2012-01-06 16:50:12,219 [http-bio-8080-exec-2] DEBUG http.headers - >> Proxy-Connection:Keep-Alive
2012-01-06 16:50:12,219 [http-bio-8080-exec-2] DEBUG http.headers - >> Cookie:ASPSESSIONIDSSTTACTA = NFJKHEDRFGTKCGFEHGFKOANP
2012-01-06 16:50:12,219 [http-bio-8080-exec-2] DEBUG http.headers - >> Cookie2:$ Version = 1
2012-01-06 16:50:12,219 [http-bio-8080-exec-2] DEBUG http.headers - >> Accept-Encoding:gzip,deflate
2012-01-06 16:50:12,219 [http-bio-8080-exec-2] DEBUG http.wire - >> postbody
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - << HTTP / 1.1 200 OK [EOL]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - << 日期:周五,2012年1月6日15:50:14 GMT [EOL]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - << 服务器:Microsoft-IIS / 6.0 [EOL]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - << X-Powered-By:ASP.NET [EOL]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - << Content-Type:text / html [EOL]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - << Cache-control:private [EOL]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - << Via:1.1 BAYEC-BC-20 [EOL]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - << Transfer-Encoding:chunked [EOL]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - << Proxy-Connection:Keep-Alive [EOL]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - << Connection:Keep-Alive [EOL]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - << 内容编码:gzip [EOL]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - << [EOL]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.headers - << HTTP / 1.1 200 OK
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.headers - <<日期:星期五,2012年1月6日15:50:14 GMT
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.headers - << Server:Microsoft-IIS / 6.0
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.headers - << X-Powered-By:ASP.NET
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.headers - << Content-Type:text / html
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.headers - << Cache-control:private
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.headers - << Via:1.1 BAYEC-BC-20
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.headers - << Transfer-Encoding:chunked
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.headers - << Proxy-Connection:Keep-Alive
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.headers - << Connection:Keep-Alive
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.headers - <<内容编码:gzip
[Date:Fri,06 Jan 2012 15:50:14 GMT,Server:Microsoft-IIS / 6.0,X-Powered-By:ASP.NET,Content-Type:text / html, Cache-control:private,Via:1.1 BAYEC-BC-20,Transfer-Encoding:chunked,Proxy-Connection:Keep-Alive,Connection:Keep-Alive,Content-Encoding:gzip]
Content-Type:text / html
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - << 226 [EOL]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - << [0x1f]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - << [0x8e]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - << [0x2]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - << [0x0]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - << [0x0] [0x0] [0x0] [0x0] [0x4] [0xb]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http。线 - << [为0x9c] S [0xc1] [为0x8E] [0xda] 0 [0×10] G [0xbd] W [0xda] PS [0xe9] [0xA5的] [0xc1] E [0xd5] [和0xAA] K [将0xEB] [0xa4] ZH [0x16] [为0x1] BI [0xee] [0xc8] $ [0x3] [0xb1:J [0x92]`-O [0×10] |![0xf2] [0xee] W [0xd4] [0xb1] [0x3] [为0x82 ] [0xec] [0xA5的] [写入0xAD] [0x1e4] 9 [0xf6]×[0xe6] Y [写0xDE] [0x9b] [0x99] [0×87] [0xf] [0xc84] [0×10] [0xf6] [0xd1] [ 0xf7] [0xf9] N [0xf1] 2 [0x17] [0x8fa] H [0x8] [0xfb] Z [0x93] [0x1c] [0xcc]'[0xb9] [0xf0] [0xa1] [0xf7] [ 0xf5]v [0xb5] K [0x1b] [0x93] [0xce] [0xd2] y [0x14] [0xc6] [\r] [\\\
]
2012-01-06 16:50 :15,687 [http-bio-8080-exec-2] DEBUG http.wire - <Y + [0xd8] * 80 [0xea] 1 [0xd6] [0x85] IQ [0xfe]& [\ n]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - <<d [0xe0] i< K [0xd0] [0x5] [0x00] z [0xa] 0 [0xa23e] [0x81] G [0xc7] i [0x9a] [0xac] [0x9e] [0xa7] QB [0xed] [0xe5] 0xae]![0XF0] [0×10] NH [位于0xDB] [0xb3] Y [位0x95] [0×15] [0xb8] [0x97] [0xe6] [0xdf] [0xbe] W [为0x0] [0xcf] [为0xBB] [0xed ] [0X1E] [0×90] [0x93] [0X2] [0xb1] [0xf6] [0xe1] [0xd0] [均为0x88] C [0xe0的] M [0xcaa] [0×12] [0xa1] d?5 [0x8中] [0X1E ] [0xc9] [的0xDC] [0xa9] [0×83 ] J 1〜[0×90] [0xac] [0xe0的:J [0x3] [0x6从] BW [0xFE的] [0xd3] [0xd3] [0xe3] [0xc8] [0x1F的] Z [0x1d] [为0x18] [\\\
]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - << [0x94之间] [0×10] [0xc6] FZ [0XAF] [0xba] [0x91] [0xc68] [0xd1] P&安培; [0x92] [0xf9b] [0xbc] [0xf] [0xcdd] [0x1b] [0X2] [ 0xA3执行] [0xee] [0xd6] 1​​ [0xa2 7)L [和0xAA] [0xFC有] [的0xDC] [为0x1] [0×14] _ [0xef] [0xA3执行] [0xc1] [0xe9] 53 [0xb2] T [ 0xe5] = [0x18] [0x19]〜[0xf9] 6 [0x1a] = 2j [0x2] [0x1c] [0xcf2] [0x8d] Q {S [0xa9] [0x1c] T [0xe0] [\r] M [0xe6] [0x92] K [0x1d] XY [0xd5] HCH [0x94之间] [0xcbd] [0xe6] M [0x97](A [0xa8] B [0x86可以] 9 [0xc9] [0xee] [0x9d] [为0x0] [0x5的]([0XF0] B [0xa6] QU [为0xE5] .L [0x5的] *`[0xb4]; [0x19] [0x6从] Y [0x1b] [为0xE5] R [0xB5执行] [0x9c5] FF [[ 0x85】V [0xc1] [0xef] [0x94之间] N [0×10] [0xf5]`[0×83] [0xc1a] [0xd4] QD [0XA0] [0x7的] [E [0xcb] [0x93] L [0xe2] [0xd9 ] * 0x [0x7] [0x1a] [0xc] fo [0x1d] 82 [0xb8] [0xfc] 5#[0x1a] [0xb8] [0xca] [\\\
]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - <<Fyx [0xed] [位0x95] [将0xEB]#WX / [的0xf1:J [为0xBF] [0xc1] Y [0x99] [0xec] DSQ [0xe2] XPT [0×17]F [0xf7] [0x1d7] b将7H [的0x84] | [ 0XAF] [0xc6] 4ZF [的0xf1] L [0xf2] [0x9f] [0xa8] [0xb1] i的; [位于0xDB] [0x1d]} [0x91] 5H [0xc8] L [0xf] [0x9] [0x8d] [0xa2 ] 4 [0x9b] [0xac] [0xca] [0xa1] [0xed]的Fe [0X1A] K [0X AB] [和0xAA] = 9 [0xae] [为0xBB] [0xe3] NUM [\r] [0x8d] [0x19] [0X1E] [0xfd] [0x9] f] [0XB] Z\(;![0x1d ] [0xba]'O [0×90] [0XAF] [0xec]取代; [值为0x8F] q [0xec] B [0xc7] [0xe9] Z61 [0x93] [0xd3] 3 [值为0x8F]&安培; [0xd1] 4J [ 0xa3] y [0xcf] [0x9c] [0xbc] [0xc4] [0xeb] h [0x9c9] [0x92] [0x9e] [0xd9] [0x80],V [0xf3]
2012-01-06 16 :50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - < [0xa4]在[0xbcd] [0×17] [0xc9] [0xaf2] O [0xc1e] [0x1b] [的0xDC] [0x16] [0xA5的] [0x3] [0xca1] 7SB [位于0xDB]9吨[0x489] [0xfd] [0x1] [0x0] [0x0] [0xff] [0xff]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - < < [\r]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - << [\\\
]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - << 0 [EOL]
2012-01-06 16:50:15,687 [http-bio-8080-exec-2] DEBUG http.wire - << [EOL]

所以我猜这个问题来自这样的事实:

 传输编码:分块
内容编码:gzip

是否有另一种方法可以做到这一点?
我做错了吗?
我尝试了一段时间的谷歌搜索,并没有找到一个好的主角。
在我看来,HTTPBuilder lib在关闭结束后获取实体内容,但是一旦我不在关闭状态,我就无法访问实体内容(例外是:无法访问封闭流)



我真的很感谢这方面的帮助;) 使用HTTPBuilder的()方法。

  http.contentEncoding = ContentEncoding.Type.GZIP 

code>

这应该可以解决您的问题。


I need to send a POST request to a web server and be able to read the response sent by said server.I tried using the HTTPBuilder lib with this code :

def http = new HTTPBuilder('http://myServer/')
http.setProxy("Proxy_IP", 8080, "http")
postBody = [cmd:'e',format:'sep',c:'a',b:'b',t:'u',r:'r',kl:'lop']

    http.post( body: postBody,
               requestContentType: URLENC ){ resp ->
     HttpEntity he = resp.getEntity()
     println "${resp.getAllHeaders()}"
     println he.getContentType()
     println "${resp.getEntity().getContent()}"
    }

I get an exception when this code gets executed :

ERROR errors.GrailsExceptionResolver  - EOFException occurred when processing request: [GET] /PROJECT/home/index
Unexpected end of ZLIB input stream. Stacktrace follows:
Message: Unexpected end of ZLIB input stream
    Line | Method
->>  240 | fill      in java.util.zip.InflaterInputStream
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    158 | read      in     ''
|    116 | read . .  in java.util.zip.GZIPInputStream
|    138 | read      in org.apache.http.conn.EofSensorInputStream
|    184 | read . .  in java.io.InputStreamReader
|    140 | read      in java.io.Reader

I turned the debug on for wire and headers and this is what I get :

2012-01-06 16:50:12,219 ["http-bio-8080"-exec-2] DEBUG http.wire  - >> "Accept: */*[EOL]"
2012-01-06 16:50:12,219 ["http-bio-8080"-exec-2] DEBUG http.wire  - >> "Content-Length: 160[EOL]"
2012-01-06 16:50:12,219 ["http-bio-8080"-exec-2] DEBUG http.wire  - >> "Content-Type: application/x-www-form-urlencoded[EOL]"
2012-01-06 16:50:12,219 ["http-bio-8080"-exec-2] DEBUG http.wire  - >> "Host: myServer[EOL]"
2012-01-06 16:50:12,219 ["http-bio-8080"-exec-2] DEBUG http.wire  - >> "Proxy-Connection: Keep-Alive[EOL]"
2012-01-06 16:50:12,219 ["http-bio-8080"-exec-2] DEBUG http.wire  - >> "Cookie: ASPSESSIONIDSSTTACTA=NFJKHEDRFGTKCGFEHGFKOANP[EOL]"
2012-01-06 16:50:12,219 ["http-bio-8080"-exec-2] DEBUG http.wire  - >> "Cookie2: $Version=1[EOL]"
2012-01-06 16:50:12,219 ["http-bio-8080"-exec-2] DEBUG http.wire  - >> "Accept-Encoding: gzip,deflate[EOL]"
2012-01-06 16:50:12,219 ["http-bio-8080"-exec-2] DEBUG http.wire  - >> "[EOL]"
2012-01-06 16:50:12,219 ["http-bio-8080"-exec-2] DEBUG http.headers  - >> POST myUrl HTTP/1.1
2012-01-06 16:50:12,219 ["http-bio-8080"-exec-2] DEBUG http.headers  - >> Accept: */*
2012-01-06 16:50:12,219 ["http-bio-8080"-exec-2] DEBUG http.headers  - >> Content-Length: 160
2012-01-06 16:50:12,219 ["http-bio-8080"-exec-2] DEBUG http.headers  - >> Content-Type: application/x-www-form-urlencoded
2012-01-06 16:50:12,219 ["http-bio-8080"-exec-2] DEBUG http.headers  - >> Host: myServer
2012-01-06 16:50:12,219 ["http-bio-8080"-exec-2] DEBUG http.headers  - >> Proxy-Connection: Keep-Alive
2012-01-06 16:50:12,219 ["http-bio-8080"-exec-2] DEBUG http.headers  - >> Cookie: ASPSESSIONIDSSTTACTA=NFJKHEDRFGTKCGFEHGFKOANP
2012-01-06 16:50:12,219 ["http-bio-8080"-exec-2] DEBUG http.headers  - >> Cookie2: $Version=1
2012-01-06 16:50:12,219 ["http-bio-8080"-exec-2] DEBUG http.headers  - >> Accept-Encoding: gzip,deflate
2012-01-06 16:50:12,219 ["http-bio-8080"-exec-2] DEBUG http.wire  - >> "postbody"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "HTTP/1.1 200 OK[EOL]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "Date: Fri, 06 Jan 2012 15:50:14 GMT[EOL]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "Server: Microsoft-IIS/6.0[EOL]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "X-Powered-By: ASP.NET[EOL]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "Content-Type: text/html[EOL]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "Cache-control: private[EOL]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "Via: 1.1 BAYEC-BC-20[EOL]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "Transfer-Encoding: chunked[EOL]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "Proxy-Connection: Keep-Alive[EOL]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "Connection: Keep-Alive[EOL]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "Content-Encoding: gzip[EOL]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "[EOL]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.headers  - << HTTP/1.1 200 OK
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.headers  - << Date: Fri, 06 Jan 2012 15:50:14 GMT
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.headers  - << Server: Microsoft-IIS/6.0
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.headers  - << X-Powered-By: ASP.NET
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.headers  - << Content-Type: text/html
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.headers  - << Cache-control: private
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.headers  - << Via: 1.1 BAYEC-BC-20
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.headers  - << Transfer-Encoding: chunked
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.headers  - << Proxy-Connection: Keep-Alive
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.headers  - << Connection: Keep-Alive
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.headers  - << Content-Encoding: gzip
[Date: Fri, 06 Jan 2012 15:50:14 GMT, Server: Microsoft-IIS/6.0, X-Powered-By: ASP.NET, Content-Type: text/html, Cache-control: private, Via: 1.1 BAYEC-BC-20, Transfer-Encoding: chunked, Proxy-Connection: Keep-Alive, Connection: Keep-Alive, Content-Encoding: gzip]
Content-Type: text/html
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "226[EOL]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "[0x1f]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "[0x8e]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "[0x2]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "[0x0]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "[0x0][0x0][0x0][0x0][0x4][0xb]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "[0x9c]S[0xc1][0x8e][0xda]0[0x10]G[0xbd]W[0xda]ps[0xe9][0xa5][0xc1]E[0xd5][0xaa]K[0xeb][0xa4]Zh[0x16]![0x1]BI[0xee][0xc8]$[0x3][0xb1]j[0x92]`O[0x10]|[0xf2][0xee]W[0xd4][0xb1][0x3][0x82][0xec][0xa5][0xad][0x1e4]9[0xf6]x[0xe6]y[0xde][0x9b][0x99][0x87][0xf][0xc84][0x10][0xf6][0xd1][0xf7][0xf9]N[0xf1]2[0x17][0x8fa]H [0x8][0xfb]Z[0x93][0x1c][0xcc]'[0xb9][0xf0][0xfd][0xf0][0xa1][0xf5]"v[0xb5]K[0x1b][0x93][0xce][0xd2]y[0x14][0xc6][\r][\n]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "Y+[0xd8]*80[0xea]l[0xd6][0x85]IQ[0xfe]&[\n]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "d[0xe0]i<K[0xd0][0x5][0x034]z[0xa4]0[0xa23e][0x81]G[0xc7]i[0x9a][0xac][0x9e][0xa7]QB[0xed][0xe5] [0xd3][0xda]#x[0xae]![0xf0][0x10]NH[0xdb][0xb3]y[0x95][0x15][0xb8][0x97][0xe6][0xdf][0xbe]W[0x0][0xcf][0xbb][0xed][0x1e][0x90][0x93][0x2][0xb1][0xf6][0xe1][0xd0][0x88]c[0xe0]M[0xcaa][0x12][0xa1]D?5[0x8][0x1e][0xc9][0xdc][0xa9][0x83]j!~[0x90][0xac][0xe0]J[0x3][0x6]BW[0xfe][0xd3][0xd3][0xe3][0xc8][0x1f]z[0x1d][0x18][\n]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "[0x94][0x10][0xc6]fz[0xaf][0xba][0x91][0xc68][0xd1]P&[0x92][0xf9b][0xbc][0xf][0xcdd][0x1b][0x2][0xa3][0xee][0xd6]1[0xa2]7)l[0xaa][0xfc][0xdc][0x1][0x14]_[0xef][0xa3]?[0xc1][0xe9]53[0xb2]T[0xe5]=[0x18][0x19]~[0xf9]6[0x1a]=2j[0x2][0x1c] [0xcf2][0x8d]Q{S[0xa9][0x1c]T[0xe0][\r]M[0xe6][0x92]k[0x1d]xY[0xd5]Hch[0x94][0xcbd][0xe6]M[0x97](a[0xa8]B[0x86]9[0xc9][0xee][0x9d][0x0][0x5]([0xf0]B[0xa6]QU[0xe5].L[0x5]*`[0xb4];[0x19][0x6]y[0x1b][0xe5]r[0xb5][0x9c5]fF;[[0x85]V[0xc1][0xef][0x94]n[0x10][0xf5]`[0x83][0xc1a][0xd4]Qd[0xa0][0x7][e[0xcb][0x93]L[0xe2][0xd9]*M(o[0xb0][0x82][0x13]d[0xfa] [0x7]\[0xd7]?[0xcb]foj[0x1d]82^[0xb8][0xfc]5#[0x1a][0xb8][0xca][\n]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "Fyx[0xed][0x95][0xeb]#wX/[0xf1]J[0xbf][0xc1]Y[0x99][0xec]dsq[0xe2]xPT[0x17]"f[0xf7][0x1d7]b<7h[0x84]|[0xaf][0xc6]4ZF[0xf1]l[0xf2][0x9f][0xa8][0xb1]i;[0xdb][0x1d]}[0x91]5H[0xc8]L[0xf][0x9][0x8d][0xa2]4[0x9b][0xac][0xca][0xa1][0xed]Fe[0x1a]k[0xab][0xaa]=9[0xae][0xbb][0xe3]NUM[\r][0x8d][0x19][0x1e][0xfd].[0x9]j[0xb]!Z\(;[0x1d][0xba]'o[0x90][0xaf][0xec]>;[0x8f]q[0xec]B[0xc7][0xe9]z61[0x93][0xd3]3[0x8f]&[0xd1]4J[0xa3]y[0xcf][0x9c][0xbc][0xc4][0xeb]h[0x9c9][0x92][0x9e][0xd9][0x80],V[0xf3]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "[0xa4]on[0xbcd][0x17][0xc9][0xaf2]o[0xc1e][0x1b][0xdc][0x16][0xa5][0x3][0xca1]7SB[0xdb]9t[0x489][0xfd][0x1][0x0][0x0][0xff][0xff]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "[\r]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "[\n]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "0[EOL]"
2012-01-06 16:50:15,687 ["http-bio-8080"-exec-2] DEBUG http.wire  - << "[EOL]"

So I guess the problem comes from the fact that the response is sent with :

Transfer-Encoding: chunked
Content-Encoding: gzip

Is there another way to do this ?Am I doing it wrong ?I tried googling for some time and did not find a good lead.It seems to me that the HTTPBuilder lib is getting the entity content after the end of the closure but once I am out of that closure, I cannot access the entity content (exception is : Cannot access closed stream)

I really would appreciate help on this one ;)

解决方案

Try using HTTPBuilder's setContentEncoding() method.

http.contentEncoding = ContentEncoding.Type.GZIP

That should solve your problem.

这篇关于Groovy HTTPBuilder:从GZIPed分块响应获取实体内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 06:53