@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1')
import groovyx.net.http.*
import org.apache.http.auth.*
import org.apache.http.impl.client.*
import org.apache.http.client.params.*
import org.apache.http.auth.params.*
import groovy.xml.*
http.request(Method.GET, ContentType.TEXT ) { req ->
uri.path = '/api/v1/UserStories/'
headers.'User-Agent' = "Mozilla/5.0 Firefox/3.0.4"
headers.Accept = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
headers.Connection = "keep-alive"
headers.'Authorization' = "Basic ${"username:password".bytes.encodeBase64().toString()}"
response.success = { resp, reader ->
assert resp.statusLine.statusCode == 200
println "Got response: ${resp.statusLine}"
println "Content-Type: ${resp.headers.'Content-Type'}"
println reader.text
}
response.'404' = {
println 'Not found'
}
}
Im getting an error:
Caught: groovyx.net.http.HttpResponseException: Unauthorized
groovyx.net.http.HttpResponseException: Unauthorized
Does the basic authentication works?
Cheers,
Rafael Gutierrez