2017-04-06 1 views
0

Ich möchte asynchrone Anfragen an meinen Server senden, indem ich Unirest verwende.Das Ausführen asynchroner Anfragen mit Unirest gibt ZipException zurück: Nicht im GZIP-Format

Dies ist mein Testcode:

public void unirestTest() throws InterruptedException, ExecutionException { 
     Unirest.get("https://jsonplaceholder.typicode.com/posts/1") 
       .header(CONTENT_TYPE, APPLICATION_JSON.toString()) 
       .asJsonAsync(new Callback<JsonNode>() { 
           public void failed(UnirestException e) { 
            e.printStackTrace(); 
           } 

           public void completed(HttpResponse<JsonNode> response) { 
            System.out.println("OK"); 
           } 

           public void cancelled() { 
            System.out.println("Request has been canceled."); 
           } 
          } 
       ).get(); 
    } 

Dies ist, was ich in der Konsole:

Connected to the target VM, address: '127.0.0.1:64120', transport: 'socket' 
02:09:15.263 [main] DEBUG org.apache.http.impl.nio.client.MainClientExec - [exchange: 1] start execution 
02:09:15.294 [main] DEBUG org.apache.http.client.protocol.RequestAddCookies - CookieSpec selected: default 
02:09:15.341 [main] DEBUG org.apache.http.client.protocol.RequestAuthCache - Auth cache not set in the context 
02:09:15.341 [main] DEBUG org.apache.http.impl.nio.client.InternalHttpAsyncClient - [exchange: 1] Request connection for {s}->https://jsonplaceholder.typicode.com:443 
02:09:15.356 [main] DEBUG org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager - Connection request: [route: {s}->https://jsonplaceholder.typicode.com:443][total kept alive: 0; route allocated: 0 of 20; total allocated: 0 of 200] 
02:09:16.394 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager - Connection leased: [id: http-outgoing-0][route: {s}->https://jsonplaceholder.typicode.com:443][total kept alive: 0; route allocated: 1 of 20; total allocated: 1 of 200] 
02:09:16.394 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.client.InternalHttpAsyncClient - [exchange: 1] Connection allocated: CPoolProxy{http-outgoing-0 [ACTIVE]} 
02:09:16.394 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionImpl - http-outgoing-0 192.168.189.147:64147<->104.31.86.157:443[ACTIVE][r:]: Set attribute http.nio.exchange-handler 
02:09:16.394 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionImpl - http-outgoing-0 192.168.189.147:64147<->104.31.86.157:443[ACTIVE][rw:]: Event set [w] 
02:09:16.394 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionImpl - http-outgoing-0 192.168.189.147:64147<->104.31.86.157:443[ACTIVE][rw:]: Set timeout 0 
02:09:16.394 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.client.InternalIODispatch - http-outgoing-0 [ACTIVE]: Connected 
02:09:16.394 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionImpl - http-outgoing-0 192.168.189.147:64147<->104.31.86.157:443[ACTIVE][rw:]: Set attribute http.nio.http-exchange-state 
02:09:16.394 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.client.InternalHttpAsyncClient - Start connection routing 
02:09:16.552 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionImpl - http-outgoing-0 Upgrade session 192.168.189.147:64147<->104.31.86.157:443[ACTIVE][rw:][ACTIVE][rw][NEED_UNWRAP][0][0][235][0] 
02:09:16.553 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.client.MainClientExec - Connection route established 
02:09:16.553 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.client.MainClientExec - [exchange: 1] Attempt 1 to execute request 
02:09:16.553 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.client.MainClientExec - Target auth state: UNCHALLENGED 
02:09:16.554 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.client.MainClientExec - Proxy auth state: UNCHALLENGED 
02:09:16.554 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionImpl - http-outgoing-0 192.168.189.147:64147<->104.31.86.157:443[ACTIVE][rw:][ACTIVE][rw][NEED_UNWRAP][0][0][235][0]: Set timeout 60000 
02:09:16.554 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 >> GET /posts/1 HTTP/1.1 
02:09:16.554 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 >> accept-encoding: gzip 
02:09:16.555 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Type: application/json; charset=UTF-8 
02:09:16.555 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 >> user-agent: unirest-java/1.3.11 
02:09:16.555 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 >> Host: jsonplaceholder.typicode.com 
02:09:16.555 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 >> Connection: Keep-Alive 
02:09:16.556 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionImpl - http-outgoing-0 192.168.189.147:64147<->104.31.86.157:443[ACTIVE][rw:][ACTIVE][rw][NEED_UNWRAP][0][0][235][0]: Event set [w] 
02:09:16.556 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.client.MainClientExec - [exchange: 1] Request completed 
02:09:16.659 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionImpl - http-outgoing-0 192.168.189.147:64147<->104.31.86.157:443[ACTIVE][rw:w][ACTIVE][rw][NOT_HANDSHAKING][0][0][217][0]: 188 bytes written 
02:09:16.659 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 >> "GET /posts/1 HTTP/1.1[\r][\n]" 
02:09:16.659 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 >> "accept-encoding: gzip[\r][\n]" 
02:09:16.659 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Type: application/json; charset=UTF-8[\r][\n]" 
02:09:16.659 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 >> "user-agent: unirest-java/1.3.11[\r][\n]" 
02:09:16.659 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Host: jsonplaceholder.typicode.com[\r][\n]" 
02:09:16.659 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]" 
02:09:16.659 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]" 
02:09:16.660 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.client.InternalIODispatch - http-outgoing-0 [ACTIVE] Request ready 
02:09:16.660 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionImpl - http-outgoing-0 192.168.189.147:64147<->104.31.86.157:443[ACTIVE][r:w][ACTIVE][r][NOT_HANDSHAKING][0][0][0][0]: Event cleared [w] 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionImpl - http-outgoing-0 192.168.189.147:64147<->104.31.86.157:443[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][0][0][0][0]: 887 bytes read 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 200 OK[\r][\n]" 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "Date: Thu, 06 Apr 2017 00:09:07 GMT[\r][\n]" 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Type: application/json; charset=utf-8[\r][\n]" 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "Transfer-Encoding: chunked[\r][\n]" 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "Connection: keep-alive[\r][\n]" 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "Set-Cookie: __cfduid=dfa98af248364fb21c08736140224a1321491437347; expires=Fri, 06-Apr-18 00:09:07 GMT; path=/; domain=.typicode.com; HttpOnly[\r][\n]" 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Powered-By: Express[\r][\n]" 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "Vary: Accept-Encoding[\r][\n]" 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "Access-Control-Allow-Credentials: true[\r][\n]" 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "Cache-Control: public, max-age=14400[\r][\n]" 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "Pragma: no-cache[\r][\n]" 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "Expires: Thu, 06 Apr 2017 04:09:07 GMT[\r][\n]" 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Content-Type-Options: nosniff[\r][\n]" 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "Etag: W/"124-yiKdLzqO5gfBrJFrcdJ8Yq0LGnU"[\r][\n]" 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "Via: 1.1 vegur[\r][\n]" 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "CF-Cache-Status: HIT[\r][\n]" 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "Server: cloudflare-nginx[\r][\n]" 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "CF-RAY: 34b0843afbaf15dd-FRA[\r][\n]" 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Encoding: gzip[\r][\n]" 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "[\r][\n]" 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "ca[\r][\n]" 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "[0x1f][0xffffff8b][0x8][0x0][0x0][0x0][0x0][0x0][0x0][0x3]U[0xffffff8f]Kj[0x4]A[0xc]C[0xfffffff7]s[\n]" 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "Q[0xffffffeb]l[0xffffffb2][0xffffff9d][0x1b][0xffffffe4][0xe][0xffffffbd]q\[\n]" 
02:09:16.716 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "c[0xffffffe8][0xfffffffa][0xffffff8c][0xffffffcb][0x1e]&[0xffffff84][0xffffffdc]=tC[0x8][0x1]#$[0xffffff90][0x1f][0xffffffe8][0xffffffeb][0x2][0xffffff94]\[0xfffffff4][0xffffffb7]Z[0xffffffae]x}9[0xffffffa2][0xfffffffd][0xffffffd9][0xffffffb0][0xffffffd8]Y[0xffffffae](+{@2[0xfffffff0]!J'[0xffffff9c][0xffffff93][0xfffffffb].[0xffffff81][0xffffffe9][0xffffffe3]a[0xffffff95]=0T[0xffffff85]*a[0xffffffe0]S9#[0xffffffdd]0f[0xffffffd8]8[0xffffffca][0xffffffce][0x1b]{[0xffffffa5][[0xffffff94][0x13][0xfffffffc]>[0xffffffea][0xffffffe7][0xffffffc1][0xffffffbd][0xffffffa7][0x9][0x18]X[0xffffffb9][0xffffffd4][0xffffffa6][0xffffffc5][0xffffffd6][0x1d][0xffffff9c][0xffffff9a]Kz[0x15]BG_[0xffffffbc]g[0xfffffff6]H[0x7][0xffffff9f][0xffffff93][0xffffffd5][0xffffffe2]|[0xffffffd3]l[[0xffffffff][0xffffff87]G[0x1b];W[0xffffff98][0x10][0x19][0xffffffc7][0xffffffdd]S[0x16]b[0xffffff84][0xffffffb4][0xffffffad][0xfffffff7][0xffffffb1][0xffffffc2][0xffffffb3][0xffffffc1]y([0xffffffd7]9[0xffffff89][\r][0xffffffe7]:g[0x3][0x1f][0xffffffec][0xffffffc6][0xffffff80][0xffffffb8][0xffffffde],[0xffffffa8]1[0xffffffca][0xffffffe5][0xfffffffb][0x7][0x15][0xffffffc6][0xffffff93][0xffffffe8]$[0x1][0x0][0x0][\r][\n]" 
02:09:16.731 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "0[\r][\n]" 
02:09:16.731 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "[\r][\n]" 
02:09:16.731 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 << HTTP/1.1 200 OK 
02:09:16.731 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 << Date: Thu, 06 Apr 2017 00:09:07 GMT 
02:09:16.731 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 << Content-Type: application/json; charset=utf-8 
02:09:16.731 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 << Transfer-Encoding: chunked 
02:09:16.731 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 << Connection: keep-alive 
02:09:16.731 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 << Set-Cookie: __cfduid=dfa98af248364fb21c08736140224a1321491437347; expires=Fri, 06-Apr-18 00:09:07 GMT; path=/; domain=.typicode.com; HttpOnly 
02:09:16.731 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 << X-Powered-By: Express 
02:09:16.731 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 << Vary: Accept-Encoding 
02:09:16.731 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 << Access-Control-Allow-Credentials: true 
02:09:16.731 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 << Cache-Control: public, max-age=14400 
02:09:16.731 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 << Pragma: no-cache 
02:09:16.731 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 << Expires: Thu, 06 Apr 2017 04:09:07 GMT 
02:09:16.731 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 << X-Content-Type-Options: nosniff 
02:09:16.731 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 << Etag: W/"124-yiKdLzqO5gfBrJFrcdJ8Yq0LGnU" 
02:09:16.731 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 << Via: 1.1 vegur 
02:09:16.731 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 << CF-Cache-Status: HIT 
02:09:16.731 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 << Server: cloudflare-nginx 
02:09:16.731 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 << CF-RAY: 34b0843afbaf15dd-FRA 
02:09:16.731 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 << Content-Encoding: gzip 
02:09:16.731 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.client.InternalIODispatch - http-outgoing-0 [ACTIVE(213)] Response received 
02:09:16.731 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.client.MainClientExec - [exchange: 1] Response received HTTP/1.1 200 OK 
02:09:16.809 [I/O dispatcher 1] DEBUG org.apache.http.client.protocol.ResponseProcessCookies - Cookie accepted [__cfduid="dfa98af248364fb21c08736140224a1321491437347", version:0, domain:typicode.com, path:/, expiry:Fri Apr 06 02:09:07 CEST 2018] 
02:09:16.809 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.client.InternalIODispatch - http-outgoing-0 [ACTIVE(213)] Input ready 
02:09:16.809 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.client.MainClientExec - [exchange: 1] Consume content 
02:09:16.809 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionImpl - http-outgoing-0 192.168.189.147:64147<->104.31.86.157:443[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][0][0][0][0]: 0 bytes read 
02:09:16.809 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionImpl - http-outgoing-0 192.168.189.147:64147<->104.31.86.157:443[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][0][0][0][0]: 0 bytes read 
02:09:16.809 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionImpl - http-outgoing-0 192.168.189.147:64147<->104.31.86.157:443[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][0][0][0][0]: 0 bytes read 
02:09:16.809 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.client.InternalHttpAsyncClient - [exchange: 1] Connection can be kept alive indefinitely 
02:09:16.809 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.client.MainClientExec - [exchange: 1] Response processed 
02:09:16.809 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.client.InternalHttpAsyncClient - [exchange: 1] releasing connection 
02:09:16.809 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionImpl - http-outgoing-0 192.168.189.147:64147<->104.31.86.157:443[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][0][0][0][0]: Remove attribute http.nio.exchange-handler 
02:09:16.809 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager - Releasing connection: [id: http-outgoing-0][route: {s}->https://jsonplaceholder.typicode.com:443][total kept alive: 0; route allocated: 1 of 20; total allocated: 1 of 200] 
02:09:16.809 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager - Connection [id: http-outgoing-0][route: {s}->https://jsonplaceholder.typicode.com:443] can be kept alive indefinitely 
02:09:16.809 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionImpl - http-outgoing-0 192.168.189.147:64147<->104.31.86.157:443[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][0][0][0][0]: Set timeout 0 
02:09:16.809 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager - Connection released: [id: http-outgoing-0][route: {s}->https://jsonplaceholder.typicode.com:443][total kept alive: 1; route allocated: 1 of 20; total allocated: 1 of 200] 
02:09:20.463 [Thread-1] DEBUG org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager - Closing expired connections 
02:09:20.478 [Thread-0] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Closing expired connections 
02:09:22.092 [Thread-1] DEBUG org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager - Closing connections idle longer than 30 SECONDS 
02:09:22.092 [Thread-0] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Closing connections idle longer than 30 SECONDS 
02:09:22.092 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.client.InternalIODispatch - http-outgoing-0 [ACTIVE] Exception 
java.lang.RuntimeException: java.lang.RuntimeException: java.util.zip.ZipException: Not in GZIP format 
    at com.mashape.unirest.http.HttpResponse.<init>(HttpResponse.java:106) 
    at com.mashape.unirest.http.HttpClientHelper$1.completed(HttpClientHelper.java:82) 
    at com.mashape.unirest.http.HttpClientHelper$1.completed(HttpClientHelper.java:75) 
    at org.apache.http.concurrent.BasicFuture.completed(BasicFuture.java:119) 
    at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.responseCompleted(DefaultClientExchangeHandlerImpl.java:177) 
    at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.processResponse(HttpAsyncRequestExecutor.java:436) 
    at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.inputReady(HttpAsyncRequestExecutor.java:326) 
    at org.apache.http.impl.nio.client.InternalRequestExecutor.inputReady(InternalRequestExecutor.java:83) 
    at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:265) 
    at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81) 
    at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39) 
    at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:121) 
    at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162) 
    at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337) 
    at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315) 
    at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276) 
    at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104) 
    at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:588) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: java.lang.RuntimeException: java.util.zip.ZipException: Not in GZIP format 
    at com.mashape.unirest.http.HttpResponse.<init>(HttpResponse.java:89) 
    ... 18 common frames omitted 
Caused by: java.util.zip.ZipException: Not in GZIP format 
    at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:165) 
    at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:79) 
    at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:91) 
    at com.mashape.unirest.http.HttpResponse.<init>(HttpResponse.java:85) 
    ... 18 common frames omitted 
02:09:22.092 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionImpl - http-outgoing-0 192.168.189.147:64147<->104.31.86.157:443[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][0][0][0][0]: Shutdown 
02:09:22.092 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.client.InternalIODispatch - http-outgoing-0 [CLOSED]: Disconnected 

java.lang.RuntimeException: java.lang.RuntimeException: java.util.zip.ZipException: Not in GZIP format 

    at com.mashape.unirest.http.HttpResponse.<init>(HttpResponse.java:106) 
    at com.mashape.unirest.http.HttpClientHelper$2.get(HttpClientHelper.java:120) 
    at com.mashape.unirest.http.HttpClientHelper$2.get(HttpClientHelper.java:104) 
    at SensorHealthCheckerTest.unirestTest(SensorHealthCheckerTest.java:68) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) 
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137) 
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117) 
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42) 
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262) 
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84) 
Caused by: java.lang.RuntimeException: java.util.zip.ZipException: Not in GZIP format 
    at com.mashape.unirest.http.HttpResponse.<init>(HttpResponse.java:89) 
    ... 25 more 
Caused by: java.util.zip.ZipException: Not in GZIP format 
    at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:165) 
    at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:79) 
    at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:91) 
    at com.mashape.unirest.http.HttpResponse.<init>(HttpResponse.java:85) 
    ... 25 more 

Disconnected from the target VM, address: '127.0.0.1:64120', transport: 'socket' 

Process finished with exit code -1 

Ich erwarte, dass diese Anforderung ohne Fehler ausgeführt werden. Ich habe festgestellt, dass es mit einigen Servern wie https://api.ipify.org?format=json funktioniert, aber es funktioniert nicht mit mir.

Der Fehler besagt, dass die Antwort nicht im GZIP-Format vorliegt. Ich weiß nicht, wie ich darauf reagieren soll. Sollte ich irgendwie das erwartete Format in Unirest ändern oder einige Header hinzufügen, so gibt der Server die Antwort im GZIP-Format zurück? Was soll ich machen?

Ich habe versucht, den Header Accept-encoding: gzip der Anfrage hinzuzufügen, aber ohne Erfolg.

+0

Haben Sie eine Lösung gefunden? – Fabian

+0

Nein, ich habe die Lösung noch nicht gefunden. – Defozo

Antwort

0

Hier ist etwas, was Sie ausprobieren könnten, wenn es für Sie arbeiten könnte. Ich nehme an, dass Sie eine Antwort im GZIP-Format erhalten, und Sie könnten den Rohteil der Antwort als InputStream erhalten. Ich bin mir nicht sicher, wie Sie das für GZIP tun würden, aber zumindest könnte dies hoffentlich etwas Licht in den Himmel bringen.

MultipartBody request = Unirest.post("url"); 
Future<HttpResponse<String>> response = request.asStringAsync(new 
Callback<String>() { 

      @Override 
      public void failed(UnirestException e) { 
       // 
      } 

      @Override 
      public void completed(HttpResponse<String> response) { 
       int code = response.getStatus(); 
       //how about converting the rawbody to GZIP? 
       InputStream fileBody = response.getRawBody(); 
      } 

      @Override 
      public void cancelled() { 
       // 
      } 

     }); 
Verwandte Themen