Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

How to program with proxy

Thread view: 
moonhk - 11 Aug 2006 09:09 GMT
Below program worked before. How to program with proxy with input User
name and password ?

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

public class eproxy_tofile {
 public static void main(String[] args) {
   Properties prop = System.getProperties();
   prop.put("http.proxyHost","xx.xx.40.20");

   prop.put("http.proxyPort","8081");
   try {
       String Addr = "http://www.new-alliance.com/Naam_NAV.htm";

       URL yahoo = new URL(Addr);
       System.out.println("Conneting ... " + Addr);

       BufferedReader in = new BufferedReader(new InputStreamReader
        (yahoo.openStream()));

        String inputLine;
        while ((inputLine = in.readLine()) !=null)
          System.out.println(inputLine);
        in.close();
   }
   catch (Exception exc) {
       exc.printStackTrace();
      
      
    }

 }

}
Arne Vajhøj - 12 Aug 2006 01:28 GMT
> Below program worked before. How to program with proxy with input User
> name and password ?

Socks ?

Arne
moonhk - 12 Aug 2006 17:40 GMT
> > Below program worked before. How to program with proxy with input User
> > name and password ?
>
> Socks ?
>
> Arne

I want daily or weekly download the contents of above site. Our Company
using proxy. So need input proxy user id and password.
Arne Vajhøj - 13 Aug 2006 03:31 GMT
>>> Below program worked before. How to program with proxy with input User
>>> name and password ?
>> Socks ?
>
> I want daily or weekly download the contents of above site. Our Company
> using proxy. So need input proxy user id and password.

I ask again: are you using socks ?

Arne
moonhk - 13 Aug 2006 14:30 GMT
> >>> Below program worked before. How to program with proxy with input User
> >>> name and password ?
[quoted text clipped - 6 lines]
>
> Arne

Sorry , What is socks ?
Arne Vajhøj - 13 Aug 2006 20:51 GMT
> Sorry , What is socks ?

That is a protocol that allows username/password
for a proxy server.

Which I do not think an ordinary HTTP proxy does.

But we can change the question: how do you
configure your browser to go out through that
firewall ? And how does the browser get the
username/password ?

Arne
moonhk - 14 Aug 2006 02:22 GMT
> > Sorry , What is socks ?
>
[quoted text clipped - 9 lines]
>
> Arne
Checked with our Administrator, it is proxy server setting. Need to
input username/password in Browser.
Arne Vajhøj - 14 Aug 2006 02:39 GMT
> Checked with our Administrator, it is proxy server setting. Need to
> input username/password in Browser.

BASIC authentication ?  (popup in browser ?)

Try with:

Authenticator.setDefault(new MyAuthenticator());

where:

class MyAuthenticator extends Authenticator {
   protected PasswordAuthentication getPasswordAuthentication() {
      return new PasswordAuthentication("xxxx", "xxxx".toCharArray());
   }
}

but I think it is a bit unusual to use HTTP BASIC authentication
with a proxy server.

Arne
moonhk - 14 Aug 2006 04:00 GMT
> > Checked with our Administrator, it is proxy server setting. Need to
> > input username/password in Browser.
[quoted text clipped - 17 lines]
>
> Arne

try. But not work. At home  below java coding is worked.

C:\Example\javaux\net>java eproxy_tofile
Conneting ... http://www.new-alliance.com/Naam_NAV.htm
java.io.IOException: Server returned HTTP response code: 500 for URL:
http://www.new-alliance.com/Naam_NAV.htm
       at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:800)
       at java.net.URL.openStream(URL.java:913)
       at eproxy_tofile.main(eproxy_tofile.java:53)

C:\Example\javaux\net>

/*

eproxy_tofile.java
2006/08/14 eric.leung

Environment variable set to
* CLASSPATH=c:\j2sdk1.4.1_01\lib\classes.zip;c:\example;.
*
*/

import java.util.Properties;
import java.io.*;
import java.net.*;
import java.net.Authenticator;

public class eproxy_tofile {
 public static void main(String[] args) {
   Properties systemSettings = System.getProperties();

class MyAuthenticator extends Authenticator {
   protected PasswordAuthentication getPasswordAuthentication() {
      return new PasswordAuthentication("xxx", "xxx".toCharArray());
   }

}
     // String host,port,userid,passwd;

    systemSettings.put("proxySet","true");
       systemSettings.put("http.proxyHost",host);
       systemSettings.put("http.proxyPort",port);

  // System.setProperty("https.proxyUserName",userid);
  // System.setProperty("https.proxyPassword",passwd);

       System.setProperties(systemSettings);

        Authenticator.setDefault(new MyAuthenticator());

   try {

      String Addr = "http://www.new-alliance.com/Naam_NAV.htm";

       URL yahoo = new URL(Addr);
       System.out.println("Conneting ... " + Addr);

       BufferedReader in = new BufferedReader(new InputStreamReader
        (yahoo.openStream()));

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

   }
   catch (Exception exc) {
       exc.printStackTrace();
      
      
    }

 }

}
EJP - 13 Aug 2006 06:32 GMT
> I want daily or weekly download the contents of above site. Our Company
> using proxy. So need input proxy user id and password.

Java.net.Authenticator


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.