2012-01-06 2 views
7

웹 서버에 POST 요청을 보내고 해당 서버에서 보낸 응답을 읽을 수 있어야합니다.Groovy HTTPBuilder : GZIP 청크 응답에서 엔티티 컨텐트 얻기

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()}" 
    } 

는이 코드가 실행됩니다 예외가 : 는이 코드로 HTTPBuilder lib 디렉토리를 사용하여 시도 내가 와이어와 헤더에 디버그를 설정하고 이것이 내가 무엇을 얻을

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 

:

:

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]" 

그래서 나는 문제는 응답이 함께 전송된다는 사실에서 오는 것 같아요

Transfer-Encoding: chunked 
Content-Encoding: gzip 

다른 방법이 있습니까? 내가 잘못하고 있니? 나는 인터넷 검색을 시도하고 좋은 리드를 찾지 못했습니다. HTTPBuilder lib가 엔티티 컨텐츠를 닫는 중일 것 같지만 일단 닫으면 엔티티 컨텐츠에 액세스 할 수 없습니다 (예외 : 닫힌 스트림에 액세스 할 수 없음)

이것에 대한 도움을 주시면 감사하겠습니다.)

답변

5

응답을 보낼 수 있습니다.

http.contentEncoding = ContentEncoding.Type.GZIP 

그러면 문제가 해결됩니다.

0

hm. 확실하지 않지만 응답을 보내야합니까 chunked?

AFAIK, chunked는 서버가 여러 부분으로 응답을 보내는 것을 의미합니다. 예외는 모든 조각을 받기 전에 기술 스택의 일부가 내용을 압축하려고 시도하는 것처럼 보입니다.

그래서 하나의 해결 방법은 HTTPBuilder의 setContentEncoding() 메소드를 사용하지 chunked

관련 문제