Hello I need to connect to an url using a basic authentication with Groovy, I would prefer to achieve this without using any libraries, because in our project we have scan for vulnerabilities and some times we faced problems when we include a new library. I was following the next examples:
def connection = new URL( "https://jsonplaceholder.typicode.com/posts")
.openConnection() as HttpURLConnection
// set some headers
connection.setRequestProperty( 'User-Agent', 'groovy-2.4.4' )
connection.setRequestProperty( 'Accept', 'application/json' )
// get the response code - automatically sends the request
println connection.responseCode + ": " + connection.inputStream.text
It worked but in my case I need to connect with a basic authentication (username and password). I haven't seen examples related.
Any ideas?
Thanks!
