using groovy http-builder in preemptive mode

不想你离开。 提交于 2019-12-02 20:31:25

Based on a JIRA issue you can do something like that :

def http = new RESTClient('http://awesomeUrl/')

http.client.addRequestInterceptor(new HttpRequestInterceptor() {
    void process(HttpRequest httpRequest, HttpContext httpContext) {
        httpRequest.addHeader('Authorization', 'Basic ' + 'myUsername:myPassword'.bytes.encodeBase64().toString())
    }
})

def response = http.get(path: "aResource")

println response.data.text

You can also solve it groovy style with

http = new RESTClient('http://awesomeUrl/')
http.headers['Authorization'] = 'Basic '+"myUsername:myPassword".getBytes('iso-8859-1').encodeBase64()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!