我正在开始 java 网络编程,但我总是得到以下代码的 Connect Reset 异常:
import java.io.*;
import java.net.*;
import java.util.*;
public class Net {
public static void main()
{
try
{
// this not working ... URL url = new URL("http://localhost/test.php");
// not even the following trial
URL url = new URL("http://www.google.com.gh/");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
// Exception is thrown here
InputStream in = conn.getInputStream();
}
catch (Exception ex)
{
System.out.println(ex.getMessage());
}
}
}
我在学习过程中尝试过的所有例子都失败了。我不知道出了什么问题。请帮忙。