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 / June 2006

Tip: Looking for answers? Try searching our database.

URLConnection

Thread view: 
IveCal - 15 Jun 2006 09:41 GMT
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 - 15 Jun 2006 13:50 GMT
Hello . . . I have something to add . . . The requested URLs can be
access through IE and Firefox . . .
Gordon Beaton - 15 Jun 2006 14:10 GMT
> 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

Signature

[  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

IveCal - 15 Jun 2006 14:28 GMT
> 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 . . .
Oliver Wong - 15 Jun 2006 19:43 GMT
> 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
IveCal - 16 Jun 2006 02:22 GMT
>     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 . . .
Oliver Wong - 16 Jun 2006 14:53 GMT
>>     Could it be that one of the two IPs (the failing one) is not
>> connected
[quoted text clipped - 6 lines]
> 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


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.