Solved

Using Authenticator & httpClient

Posted on 2004-09-27
5
503 Views
Last Modified: 2006-11-17
Here is a snipet of code that I'm using to authenticate to our corporate proxy server.  I can retrieve pages no problem, but I would like to incorporate this concept into my other project which utilized httpclient to log into a web-mail server programatically and check for new messages.  My question is how to use httpclient in this context because the below snipet is using HttpURLConnection.

try{
            Properties systemProperties = System.getProperties();

            String url = "http://eng.mail.ru/",
                         proxy = "proxyserverhere",
                         port = "80",
                         username = "usernamehere",
                         password = "passwordhere";

            Authenticator.setDefault(new SimpleAuthenticator(username, password));
            URL server = new URL(url);
            systemProperties.setProperty("http.proxyHost",proxy);
            systemProperties.setProperty("http.proxyPort",port);
            HttpURLConnection connection = (
            HttpURLConnection)server.openConnection();
            connection.connect();
            InputStream in = connection.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String line = new String();
            while((line=br.readLine())!=null)
            {
                System.out.println(line);
            }
           
        }
        catch(Exception e){e.printStackTrace();}


In my other program, I'm doing the following:

PostMethod post = new PostMethod("http://eng.mail.ru/");
int responseCode = httpclient.executeMethod(post);

how could these be combined????

Thanks,
David


0
Comment
Question by:lomidien
  • 4
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Probably not that easily. I would configure the same parameters on the HttpClient
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
Comment Utility
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
0
 

Author Comment

by:lomidien
Comment Utility
Yeah, you're probably right.  Doing this through the httpClient itself seems the way to go.

Thanks,
David
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
8-)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now