URLConnection

Discussion in 'Java' started by IveCal, Jun 15, 2006.

  1. IveCal

    IveCal Guest

    Hello... I have a very big prob here. I have 2 IPs. I dunno what
    happened but when I executed the same progs in the 2 IPs: in the 1st
    IP, the prog was working but in the 2nd IP, it threw an
    java.net.UnknownHostException . . . Here is the code:

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


    public class UCDemo
    {
    public static void main(String[] args)
    {
    try
    {
    String inputLine = "";
    String resultString = "";
    URL url = new URL("http://www.internic.net");
    URLConnection uc = url.openConnection();

    if (!(uc instanceof HttpURLConnection))
    {
    System.err.println ("Wrong connection type");
    }

    BufferedReader in = new BufferedReader(new
    InputStreamReader(uc.getInputStream()));

    while ((inputLine = in.readLine()) != null)
    resultString+=inputLine;
    in.close();

    System.out.println(resultString);

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


    And here is the exception:

    java.net.UnknownHostException: www.internic.net
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
    at java.net.Socket.connect(Socket.java:507)
    at java.net.Socket.connect(Socket.java:457)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:365)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:477)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:214)
    at sun.net.www.http.HttpClient.New(HttpClient.java:287)
    at sun.net.www.http.HttpClient.New(HttpClient.java:299)
    at
    sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:792)
    at
    sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:744)
    at
    sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:669)
    at
    sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:913)
    at UCDemo.main(UCDemo.java:22)

    What went wrong?!? Please help... Thanks a lot.
    IveCal, Jun 15, 2006
    #1
    1. Advertising

  2. IveCal

    IveCal Guest

    URLConnection (Continuation)

    Hello . . . I have something to add . . . The requested URLs can be
    access through IE and Firefox . . .
    IveCal, Jun 15, 2006
    #2
    1. Advertising

  3. On 15 Jun 2006 01:41:44 -0700, IveCal wrote:
    > Hello... I have a very big prob here. I have 2 IPs. I dunno what
    > happened but when I executed the same progs in the 2 IPs: in the 1st
    > IP, the prog was working but in the 2nd IP, it threw an
    > java.net.UnknownHostException . . . Here is the code:


    Behind a firewall? Check your proxy settings.

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
    Gordon Beaton, Jun 15, 2006
    #3
  4. IveCal

    IveCal Guest

    Gordon Beaton wrote:
    >
    > Behind a firewall? Check your proxy settings.
    >
    > --
    > [ do not email me copies of your followups ]
    > g o r d o n + n e w s @ b a l d e r 1 3 . s e


    Sorry,sir but I'm not using any firewall or proxy as of the moment . . .
    IveCal, Jun 15, 2006
    #4
  5. IveCal

    Oliver Wong Guest

    "IveCal" <> wrote in message
    news:...
    > Hello... I have a very big prob here. I have 2 IPs. I dunno what
    > happened but when I executed the same progs in the 2 IPs: in the 1st
    > IP, the prog was working but in the 2nd IP, it threw an
    > java.net.UnknownHostException . . . Here is the code:
    >

    [most of the code snipped]
    > URL url = new URL("http://www.internic.net");


    Could it be that one of the two IPs (the failing one) is not connected
    to the Internet, but only to your local LAN which doesn't have a DNS or DHCP
    server?

    - Oliver
    Oliver Wong, Jun 15, 2006
    #5
  6. IveCal

    IveCal Guest

    Oliver Wong wrote:

    > Could it be that one of the two IPs (the failing one) is not connected
    > to the Internet, but only to your local LAN which doesn't have a DNS or DHCP
    > server?
    >
    > - Oliver


    The requested URLs can be accessed through IE and Firefox . . .
    The requested URLs do not work in my Java Applications . . .
    IveCal, Jun 16, 2006
    #6
  7. IveCal

    Oliver Wong Guest

    "IveCal" <> wrote in message
    news:...
    >
    > Oliver Wong wrote:
    >
    >> Could it be that one of the two IPs (the failing one) is not
    >> connected
    >> to the Internet, but only to your local LAN which doesn't have a DNS or
    >> DHCP
    >> server?
    >>
    >> - Oliver

    >
    > The requested URLs can be accessed through IE and Firefox . . .
    > The requested URLs do not work in my Java Applications . . .


    Could it be that your browsers (e.g. IE and Firefox) are intelligent
    enough know to use the IP which *IS* connected to the internet?

    For example, on my home machine, I have two NICs, and so I have 2 IP
    addresses. One of them is connected to the Internet and it's IP is something
    like 216.58.97.17, and the other one is connected to my local LAN, and is
    something like 192.168.0.1.

    There's no DNS server on the 192.168.*.* network, so if I try to resolve
    "ww.google.com", I'll fail.

    - Oliver
    Oliver Wong, Jun 16, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kristoffel

    URLConnection and proxy

    Kristoffel, Jul 27, 2003, in forum: Java
    Replies:
    0
    Views:
    1,561
    Kristoffel
    Jul 27, 2003
  2. Brock Jones
    Replies:
    0
    Views:
    2,621
    Brock Jones
    Sep 4, 2003
  3. Bronwyn Howard
    Replies:
    0
    Views:
    6,088
    Bronwyn Howard
    Oct 1, 2003
  4. dave
    Replies:
    0
    Views:
    829
  5. Replies:
    2
    Views:
    3,564
Loading...

Share This Page