1

我正在尝试将一些旧式 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 来处理基本身份验证。

4

1 回答 1

0

如果你在这里是因为 JIRA 行为不端。文档中声明的内容不起作用 - 不是由于客户端库问题,而是 JIRA 有一些特殊行为。

以下代码有效

   def builder = HttpBuilder.configure {
            request.uri = 'http://ies-iesd-jira.ies.mentorg.com:8080'
            request.contentType = 'application/json'
           // request.auth.digest("user","password", true) -->does not work with JIRA
            request.headers['Authorization'] = 'Basic ' + 'user:password'.bytes.encodeBase64()
        }
于 2017-09-09T03:48:57.287 回答