We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › Reading URLs protected with HTTP Authentication
Page Index Toggle Pages: 1
Reading URLs protected with HTTP Authentication (Read 1133 times)
Reading URLs protected with HTTP Authentication
Jun 5th, 2009, 3:20am
 
I want to read and use data from "Google Insights for Search", but the password authentication mechanism makes it impossible for me.

I found a solution for java : Quote:
If the access to the URL is protected with authentication mechanism, IOException is thrown when you try to read from InputStream associated with URLConnection. In that case, you need to use Authenticator class from java.net package.
The example code is shown below.


Code:

import java.net.*;
import java.io.*;

public class URLConnectionAuthReader {
public static void main(String[] args) throws Exception {
String username = "username";
String password = "password";
URL authurl = new URL(url);

Authenticator.setDefault(new MyAuthenticator(username, password));
URLConnection ac = authurl.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
ac.getInputStream()));
String inputLine;

while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}

protected static class MyAuthenticator extends Authenticator {
private String username, password;

public MyAuthenticator(String user, String pwd) {
username = user;
password = pwd;
}

protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password.toCharArray());
}
}
}



But I don´t know how to use it in processing or if there exists something equal for processing.

Has anybody an idea?

Thanks, Silke
Page Index Toggle Pages: 1