2017-03-17 201 views
0

我正在使用仅适用于GZIP压缩的服务。我添加了Accept头和服务,但RESTClient无法正确解析内容。如何使用RESTClient接收GZIP响应

我的代码:

def client = new RESTClient('https://rest-service-gziped.com') 
def postBody = [ somekey: "somevalue" ] 
def response = client.post(
    path: "/some-endpoint", 
    body: postBody, 
    requestContentType : ContentType.JSON, 
    headers: ["Accept-Encoding": "gzip"] 
) 

的错误消息是

Mar 17, 2017 5:48:03 PM groovyx.net.http.RESTClient handleResponse 
WARNING: Error parsing 'application/json; charset=utf-8' response 
groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object 

回答

0

只需添加以下RESTClient实现实例化后

client.setContentEncoding(ContentEncoding.Type.GZIP, ContentEncoding.Type.DEFLATE)