I'm working on a web service and I need a code for making an HTTP request in java using basic authentication. I found lots of code at the internet but no one worked as expected. Does anyone knows some library and/or link to do this?
Here is a python equivalent to what I want...
import urllib2
import base64
req = urllib2.Request('http://testeserjaum.appspot.com/rest/metadata')
req.add_header('User-Agent', 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)')
base64string = base64.encodestring('%s:%s' %('user', 'pass'))
print base64string
req.add_header("Authorization", "Basic %s" %base64string)
lol = urllib2.urlopen(req)
print lol.read()