JDK-4245323 : java.net.UnknownHostException at FtpURLConnection.connect()
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 1.2.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1999-06-09
  • Updated: 1999-06-30
  • Resolved: 1999-06-30
Related Reports
Duplicate :  
Relates :  
Description

Name: dbT83986			Date: 06/09/99

=20
ENVIRONMENT:
------------
    Connection to Internet via (MS-)Proxy-Server,=20
    Proxy-Authorization is needed.

    When i try to connect() to a FTP-URL i get the
    UnknownHostException.

    Connecting to the same Host with a http:// URL
    does work.

    Connecting to the FTP-URL via Internet-Explorer
    does work too.


ERROR MESSAGES
----------------
D:\Projekte\install>d:\app\jdk121\bin\java GetURLshort ftp://ftp.mathematik=
.uni-halle.de

java.net.UnknownHostException: ftp.mathematik.uni-halle.de
        at java.net.InetAddress.getAllByName0(Compiled Code)
        at java.net.InetAddress.getAllByName0(InetAddress.java:544)
        at java.net.InetAddress.getByName(Compiled Code)
        at java.net.Socket.<init>(Socket.java:98)
        at sun.net.NetworkClient.doConnect(NetworkClient.java:54)
        at sun.net.NetworkClient.openServer(NetworkClient.java:42)
        at sun.net.ftp.FtpClient.openServer(FtpClient.java:271)
        at sun.net.ftp.FtpClient.<init>(FtpClient.java:385)
        at sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnecti=
on.java:82)
        at GetURLshort.openURLForInput(GetURLshort.java:68)
        at GetURLshort.doit(Compiled Code)
        at GetURLshort.main(GetURLshort.java:22)

THE following does work:
----------------------

D:\Projekte\install>d:\app\jdk121\bin\java GetURLshort http://ftp.mathemati=
k.uni-halle.de
<HTML><HEAD>
<TITLE>Department of Mathematics and Computer Science</TITLE>
</HEAD>
<BODY background=3D"/icons/siegrely.jpg">

<B>
  <FONT SIZE=3D"+1">
  <A HREF=3D"http://www.uni-halle.de/">
  Martin-Luther-Universit=E4t Halle-Wittenberg</A><BR>
  </FONT>
  <FONT SIZE=3D"+2">
  Department of Mathematics and Computer Science<BR>
  </FONT>
</B>

<HR>
<h2>The WWW-Server www.mathematik.uni-halle.de has moved to
<p>
<a href=3D"http://www.mathematik.uni-halle.de">www.mathematik.uni-halle.de<=
/a>
<p>
</h2>
</BODY></HTML>


------------------
EXAMPLE PROGRAM
-------------------

// GetURLshort.java
//



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

 public class GetURLshort {

   URLConnection conn =3D null;

   public static void main (String args[]){
     GetURLshort a =3D new GetURLshort();
=09 if( args.length<1 )
=09 {
=09=09System.err.println("Usage: GetURLshort http://xx.yy.zz");
=09=09return;
=09 }

     a.doit(args);
     }

   public void doit(String args[]) {


     Properties systemSettings =3D System.getProperties();
=09 systemSettings.put("proxySet", "true");
=09 systemSettings.put("proxyHost", "999.99.999.99");=20
=09 systemSettings.put("proxyPort", "9999");
=09 System.setProperties(systemSettings);


     try {
=09   URL url =3D new URL(args[0]);


       BufferedInputStream in =3D new BufferedInputStream(
              openURLForInput(url));

=09   BufferedOutputStream out =3D new BufferedOutputStream(
=09   =09new FileOutputStream ( java.io.FileDescriptor.out ));

       byte[] bytes_read =3D new byte[1024];
       int    nr_bytes_read;
       while ((nr_bytes_read =3D in.read(bytes_read,0,bytes_read.length )) =
> 0) {
           out.write(bytes_read, 0, nr_bytes_read);
           }
=09=09out.flush();
=09=09out.close();
       }
     catch (IOException e) {
       e.printStackTrace();
       }
     }

   public InputStream openURLForInput (URL url)
        throws IOException  {


     conn =3D url.openConnection();
     conn.setDoInput (true);
=09 String encoded =3D new String("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=
");  =20

 =09 conn.setRequestProperty("Proxy-Authorization", "Basic " + encoded);

     conn.connect ();
     return conn.getInputStream();
     }
 }
----------
VERSION
----------
D:\Projekte\install>d:\app\jdk121\bin\java -version
java version "1.2.1"
Classic VM (build JDK-1.2.1-A, native threads)

D:\Projekte\\install>d:\app\jdk121\bin\java -fullversion
java full version "JDK-1.2.1-A"
----------
EOF
----------
(Review ID: 84138)=20
======================================================================

Comments
PUBLIC COMMENTS This is a duplicate of 4249722.
10-06-2004