Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Tips'n'Tricks

the-kenny edited this page Sep 13, 2010 · 1 revision

How to identify with HTTP

If you want to use a service like cloudant.com where clients have to identify themselves with http authentication (basic access authentication), you can use java.net.Authenticator to transparently authorize all connections made by HttpURLConnection (That’s what clojure-couchdb is using behind the scenes)

Here is a snippet which shows how it’s possible to identify outgoing http connections (I use this for cloudant.com):


(java.net.Authenticator/setDefault 
   (proxy [java.net.Authenticator] []
     (getPasswordAuthentication []
      (java.net.PasswordAuthentication.
       "my-username" (into-array Character/TYPE "my-password")))))

You can find more information about java.net.Authenticator here.

Clone this wiki locally