Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using Authenticator & httpClient

Posted on 2004-09-27
5
Medium Priority
?
512 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 2000 total points
ID: 12161059
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.
Suggested Courses

609 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