Friday, November 25, 2011

HTTP authentication with Scala Dispatch

I had some trouble getting basic HTTP authentication to work with the Dispatch library. The documentation and message posts that I've seen say to use the .as(username, password) function on the HTTP request. However, this did not work for me. I had to use the as_! function instead of as. Example:



I believe using as will make a request without authentication, look for a 401 response header, and then re-issue the request with authentication. The Github API, and many others I imagine, do not send a 401 response back when not authenticated.

3 comments:

Timo said...

Thank you so much for this! Saved me at least a day.

Unknown said...

Thx!!! It was very helpful for me! =)

Unknown said...

Thank you so much mate!
Saved me a whole lot of trouble