首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在HttpBuilder-NG中添加基本授权请求拦截器的正确方法

在HttpBuilder-NG中添加基本授权请求拦截器的正确方法
EN

Stack Overflow用户
提问于 2017-05-13 04:48:36
回答 1查看 838关注 0票数 1

我正在尝试将一些旧式Groovy代码转换为HttpBuilder-NG。在旧风格中,我必须做的一件事是添加请求拦截器来处理基本的授权。这就是我在旧的HttpBuilder中是如何做到的

代码语言:javascript
复制
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会在日志中记录这一点。

代码语言:javascript
复制
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和请求拦截器来处理基本的身份验证。

EN

回答 1

Stack Overflow用户

发布于 2017-09-09 11:48:57

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

下面的代码可以工作

代码语言:javascript
复制
   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()
        }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43946255

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档