我正在尝试将一些旧式 Groovy HttpBuilder 代码转换为 HttpBuilder-NG。我必须以旧方式做的一件事是添加请求拦截器来处理基本授权。这就是我在旧的 HttpBuilder 中的做法
def http = new RESTClient(url)
http.client.addRequestInterceptor(new HttpRequestInterceptor() {
void process(HttpRequest httpRequest, HttpContext httpContext) {
log.debug("Request intercepted, adding authorization")
httpRequest.addHeader('Authorization','Basic ' + "${username}:${password}".bytes.encodeBase64().toString())
}
})
return http
在HttpBuilder-NG中应该怎么做?(是的,我一直在阅读用户指南)。
2017 年 5 月 16 日更新
我问是因为使用 ApacheHttpBuilder 它在日志中得到了这个。
DEBUG - Authentication required
DEBUG - gpdevjira.broadinstitute.org:8443 requested authentication
DEBUG - Authentication schemes in the order of preference: [Negotiate, Kerberos, NTLM, Digest, Basic]
DEBUG - Challenge for Negotiate authentication scheme not available
DEBUG - Challenge for Kerberos authentication scheme not available
DEBUG - Challenge for NTLM authentication scheme not available
DEBUG - Challenge for Digest authentication scheme not available
DEBUG - Challenge for Basic authentication scheme not available
我能够使用带有请求拦截器的旧 HttpBuilder 来处理基本身份验证。