Reputation: 15
I'm making a program that reads html from a website and pulls some things from the html. When I try to start my socket I get the UnknownHostException error. It happens when I call the InetAdress method as well. I've tried multiple ways of doing this including not using the inetaddress method and it doesn't help anything. Here's what the code looks like
try {
InetAddress add = InetAddress.getByName(text);
} catch (UnknownHostException e1) {
}
try {
Socket socket = new Socket(text,80);
PrintWriter out = new PrintWriter(socket.getOutputStream());
}
Upvotes: 0
Views: 819
Reputation: 6090
Make sure you're passing just the hostname, and not the complete path to the resource you're trying to fetch. For instance, in your comment you wrote en.wikipedia.org/wiki/The_Elder_Scrolls_IV:_Oblivion
; to determine the host your Socket
should connect to, pass just en.wikipedia.org
to the InetAddress.getByName()
method.
Upvotes: 2