URLConnection

I

IveCal

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.
 
I

IveCal

Hello . . . I have something to add . . . The requested URLs can be
access through IE and Firefox . . .
 
G

Gordon Beaton

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
 
O

Oliver Wong

IveCal said:
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
 
I

IveCal

Oliver said:
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 . . .
 
O

Oliver Wong

IveCal said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top