사용자를 인증하지 않습니다 다음 코드 (더 인증 실패가 발생하지 않지만, 호출에 의한 권한의 부족으로 실패) :HTTPBuilder 기본 인증이 작동하지 않는 이유는 무엇입니까?
def remote = new HTTPBuilder("http://example.com")
remote.auth.basic('username', 'password')
remote.request(POST) { req ->
uri.path = "/do-something"
uri.query = ['with': "data"]
response.success = { resp, json ->
json ?: [:]
}
}
그러나 다음 잘 작동 :
def remote = new HTTPBuilder("http://example.com")
remote.request(POST) { req ->
uri.path = "/do-something"
uri.query = ['with': "data"]
headers.'Authorization' =
"Basic ${"username:password".bytes.encodeBase64().toString()}"
response.success = { resp, json ->
json ?: [:]
}
}
왜 ISN을 첫 번째 작품은?
방법이 실패하는 데 도움이
희망 다른 클래스에 캡슐화? 서버는 HTTP 401 상태 코드를 반환하여 기본 인증을 트리거해야합니다. 그러면 HttpBuilder는 Authorization 헤더와 함께 두 번째 요청을 보냅니다. – ataylor
그냥 작동하지 않습니다. 요청 자체는 사용자에게 작업 수행 권한이 없다는 메시지와 함께 반환됩니다. 사용자 이름과 암호를 완전히 무효로 변경할 수 있으며 같은 일이 발생합니다. –
그러면 잠재적으로 문제가 해결됩니다. http://stackoverflow.com/questions/6588256/using-groovy-using-groovy-http-builder-in-preemptive-mode –