开发者

Java URLConnection Error

This error is from a PC connected to a comcast modem. Is port blocking an issue when a person is trying to make an outbound TCP channel with a Java URL . . . the relevant code is :

URL u = new URL("mailto:someguy@gmail.com");    // make a mailto: url
URLConnection c = u.openConnection();   // make its urlconnection
c.connect();                // connect to mail host

catch (Exception e) {   // handle any exceptions, print error message
  System.err.println(e);
}

The console returns the message :

connect. Timeout = -1 ja开发者_如何学编程va.net.UnknownHostException: mailhost


MailToURLConnection is NOT in Java 6 or 7 or any earlier version. It is part of the OpenJDK implementation of J2SE specifications. Download and install OpenJDK and use that as your Java JDK and the problem will probably go away. I have checked, OpenJDK 6 has the MailToURLConnection class.


This exception java.net.UnknownHostException: mailhost is thrown to indicate that the IP address of a host could not be determined.

I reckon you might be trying to send a mail.


I cannot find any documentation but it seems URL.openConnection() above creates a sun.net.www.protocol.mailto.MailToURLConnection. Looking at the code here it creates an SmtpClient.

This creates a connection to System.getProperty("mail.host") or to "localhost" or to "mailhost". I guess the "mail.host" is not defined for you and localhost is not accepting the connection so the dns error for mailhost.

Where did find information to use "mailto:" anyway? That same place should also have the rest of usage documentation. If you were just trying something or ran into it accidentally then I would advice not to use it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜