gpt4 book ai didi

groovy - 如何获取 Groovy RestClient 失败响应的完整响应

转载 作者:行者123 更新时间:2023-12-02 11:39:23 24 4
gpt4 key购买 nike

目前,我收到 HttpResponseException,它只有 statusCode。我怎样才能获得完整的回复?

这是我正在使用的代码

restClient = new RESTClient("http://${Server}")
try {
HttpResponseDecorator resp = restClient.post(path,body,requestContentType)
as HttpResponseDecorator
return JSONObject.fromObject(resp.getData()).get("topKey","");
}
catch (HttpResponseException e) {
error(e.toString())
}

它只输出:

[oaf.error] groovyx.net.http.HttpResponseException: Internal Server Error

最佳答案

添加自定义失败响应处理程序:

        restClient = new RESTClient("http://${Server}")
restClient.handler.failure = { resp, data ->
resp.setData(data)
String headers = ""
resp.headers.each {
headers = headers+"${it.name} : ${it.value}\n"
}
throw new HttpResponseException(resp.getStatus(),"HTTP call failed. Status code: ${resp.getStatus()}\n${headers}\n"+
"Response: "+(resp as HttpResponseDecorator).getData())
}

关于groovy - 如何获取 Groovy RestClient 失败响应的完整响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28843915/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com