Solved

Using Authenticator & httpClient

Posted on 2004-09-27
5
507 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
ID: 12161009
Probably not that easily. I would configure the same parameters on the HttpClient
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 12161059
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12161079
0
 

Author Comment

by:lomidien
ID: 12161384
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
ID: 12161885
8-)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java JRE greater than 1.6 5 62
type mismatch (Object[] to double[] 4 23
hibernate example issues from command prompt 10 40
login form jsp example 2 24
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

813 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

14 Experts available now in Live!

Get 1:1 Help Now