我正在尝试将一些旧式Groovy代码转换为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和请求拦截器来处理基本的身份验证。
发布于 2017-09-09 11:48:57
如果你来这里是因为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()
}https://stackoverflow.com/questions/43946255
复制相似问题