views:

212

answers:

4
+2  Q: 

Java HTTP AUTH?

I'm trying to connect a desktop application I am writing with the del.icio.us api @ http://delicious.com/help/api and simply provide them with my username and password and to request an url to post a bookmark to my profile.

The problem I have is that I don't understand how to send my login credentials when I open a connection.

How would I go about doing this?

A: 

HttpUrlConnection allows you to perform basic authentication. The more powerful HttpClient libraru offers you more solutions (basic, digest, and NTLM - which I don't think you need).

Brian Agnew
A: 

If you just need HTTP Basic Authentication, you can form your URL like this:

http://user:[email protected]


UPDATE:

Using the example provided, this should work:

https://user:[email protected]/v1/posts/add&url=http://www.google.com&description=awesome
AJ
apparently this doesn't work anymore.. at least not with the account I made. I think it has something to do with yahoo recently taking over delicious
AFK
+1  A: 

From the site you referenced:

All /v1 api's require https requests and HTTP-Auth.

HTTP-Auth is header used in basic authentication.
In Java, you can simply put your credentials in the URL:

http://user:[email protected]/

You can verify that it was set correctly using the URL.getUserInfo() method.

jheddings
A: 

HttpURLConnection does allow you to do basic auth, but if you want more complex authentication to be able to work, give Apache HTTPClient a shot. It can seamlessly-handle http authentication schemes like Basic and Digest without you even noticing.

HTTPClient Authentication Guide

JasonWyatt