Solved

Using Authenticator & httpClient

Posted on 2004-09-27
5
508 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
check java version using powershell 13 304
how to install java on RHEL image on EC2 4 57
How do I remove an object from a 3 53
mysql jsp example issue 32 75
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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

726 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