Basic Authentication HttpClient?

667 views
Skip to first unread message

Conrad Crampton

unread,
Jul 22, 2015, 7:15:08 AM7/22/15
to vert.x
Hi,
Fairly new to vertx (done some in v2, now more in v3).
I am trying to create a HttpClient implementation in a verticle to get (and download) resources from a website. The website is protected with Basic Authentication for which I have username and password details. 
How do I pass these into the HttpClient configuration so I can programmatically access the index page (which is also protected). The intention is to traverse the links therein and download the resources.

I can't find any examples of doing this anywhere. Be grateful for a pointer.

I can do this in Apache commons httpclient, but wanted to do it the vertx way.

Many thanks
Conrad

Paulo Lopes

unread,
Jul 22, 2015, 8:10:08 AM7/22/15
to vert.x
Vert.x HttpClient does now have any specific authentication implementation, since it is a simple raw HTTP client. So if you need that then you need to implement it yourself :/ although it is not that complicated.

Basic HTTP auth is just about adding the following header:

Authorization: Basic <base64 encoded username:password>

So to sum up and repeat myself, the header should contain: "Basic" + SPACE + base64 String, where the base64 string is the digest of username + ":" + password.

Cheers,
Paulo

Conrad Crampton

unread,
Jul 22, 2015, 8:41:30 AM7/22/15
to vert.x
Hi Paulo,
Fantastic - worked like a charm.
Many thanks for the prompt response.
Conrad
Reply all
Reply to author
Forward
0 new messages