0

Looks like HTTPBuilder's behavior goes wrong when the server / api endpoint does not give a proper response. Mailgun's API does not respond 401, but instead gives something else. (Correct me if I'm wrong!)

The fact that there are no "Authentication required" headers sent, HTTPBuilder will not even try to authenticate.

I think I got the problem solved by the help of this thread: http://groovy.329449.n5.nabble.com/HTTPBuilder-Strange-behaviour-of-auth-basic-td344479.html

They suggest, that writing the authentication header manually will force the authentication each time. Needed to modify that a bit so it looks like this:

def user = 'tom' 
def pass = 'secret' 

def http = new HTTPBuilder('http://myhost.com') 
http.headers[ 'Authorization' ] = "Basic " + "$user:$pass".getBytes('iso-8859-1').encodeBase64() 

Seems to work now. Any better ideas? This looks like and perhaps is a hack.

tukkaj
  • 596
  • 1
  • 6
  • 16

1 Answers1

0

Try to use something like:

def authSite = new HTTPBuilder( 'https://some-protected-site.com/' )
authSite.auth.basic 'myUserName', 'myPassword'

Read more at: http://groovy.codehaus.org/modules/http-builder/doc/auth.html