I’ve been trying to play with the Github API in an Android app, but a couple wrenches in the machine made it a lot more difficult than anticipated. Every request I was making returned a 404. At first I thought the Android keystore didn’t have Github’s SSL cert and tried to create my own keystore. Eventually I figured out that it was basic authentication that wasn’t working correctly, and not SSL. If only Github’s API returned a 401 Unauthorized instead of a 404 Not found.
Anyway, many many hours later, I finally found this Stackoverflow answer which gave me the magic incantation for submitting an http request with basic authentication in the header:
String username = ... String password = ... UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password); HttpRequest request = ... request.addHeader(new BasicScheme().authenticate(creds, request));
I’m blogging it so I remember how to do it later.