Seems near impossible to make an authenticated request with HTTPBuilder.
Things I tried
http.auth.basic 'login', 'pass'
headers.'Authorization' =
"Basic ${"username:password".bytes.encodeBase64().toString()}"
http.setHeaders([Authorization: "Basic encodedAuthString="])
My code:
def auth = "login:pass"
String authString = auth.bytes.encodeBase64().toString()
def http = new HTTPBuilder('site.com')
http.setHeaders([Authorization: "Basic"+authString])
http.request( POST ) {
uri.path = '/path'
requestContentType = ContentType.JSON
body = someJson
response.success = { resp,reader ->
// ok
}
}
None of the above worked for me. Request always results with 401 (Unauthorized)
Have you tried setting the header inside the function, like so?
def http = new HTTPBuilder('site.com')
http.request( POST ) {
uri.path = '/path'
headers.'Authorization' = 'Basic '+authString
requestContentType = ContentType.JSON
body = someJson
response.success = { resp,reader ->
// ok
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.