我正在使用仅适用于GZIP压缩的服务。我添加了accept头和服务,但RESTClient无法正确解析内容。
我的代码:
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 :(得分:0)
在RESTClient实例化后添加以下内容
client.setContentEncoding(ContentEncoding.Type.GZIP, ContentEncoding.Type.DEFLATE)