3

I'm trying to connect a desktop application I am writing with the del.icio.us api @ Delicious 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?

2
  • Do you mean HTTP Basic Authentication? Commented Nov 7, 2009 at 16:05
  • if you look at the link for the api, the example link i would have to type into my browser to add a bookmark is api.del.icio.us/v1/posts/add&url=http://… Commented Nov 7, 2009 at 16:08

5 Answers 5

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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).

Comments

0

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

1 Comment

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
0

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

Comments

0

This Answer is ok:

public String reloadTomcatWebApplication(String user, String pwd, String urlWithParameters, boolean returnResponse){        
    URL url = null;
    try {

        url = new URL(urlWithParameters);
    } catch (MalformedURLException e) {
        System.out.println("MalformedUrlException: " + e.getMessage());
        e.printStackTrace();
        return "-1";
    }

    URLConnection uc = null;
    try {
        uc = url.openConnection();
    } catch (IOException e) {
        System.out.println("IOException: " + e.getMessage());
        e.printStackTrace(); 
        return "-12";
    }


    String userpass = user + ":" + pwd;
    String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes());

    uc.setRequestProperty ("Authorization", basicAuth);

    InputStream is = null;
    try {
        is = uc.getInputStream();
    } catch (IOException e) {
        System.out.println("IOException: " + e.getMessage());
        e.printStackTrace();
        return "-13";
    }
    if(returnResponse){
    BufferedReader buffReader = new BufferedReader(new InputStreamReader(is));
    StringBuffer response = new StringBuffer();

    String line = null;
    try {
        line = buffReader.readLine();
    } catch (IOException e) {
        e.printStackTrace();
        return "-1";
    }

    while (line != null) {
        response.append(line);
        response.append('\n');
        try {
            line = buffReader.readLine();
        } catch (IOException e) {
            System.out.println(" IOException: " + e.getMessage());
            e.printStackTrace();
            return "-14";
        }
    }

    try {
        buffReader.close();
    } catch (IOException e) {
        e.printStackTrace();
        return "-15";
    }       
    System.out.println("Response: " + response.toString());
    return response.toString();

    }               
    return "0";
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.