我正在尝试使用URL连接库编写一个连接到Twitter搜索URL(它返回一个JSON推文列表)的小型java程序。通过代理连接到Java中的URL
我这是从Java教程所采取的代码如下所示:
public static void main(String[] args) throws Exception {
URL oracle = new URL("http://search.twitter.com/search.json?q=hi");
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
,但由于某种原因,我不断收到以下异常:
in thread "main" java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
我不知道这是什么由于我写代码的方式,eclipse设置或者与我的网络有关的东西。我的代理服务器配置了Internet访问。据我所知这是正确配置,因为我得到更新,并可以通过eclipse安装新软件。我是否需要将代理信息以某种方式放在URL方法中,或者是其他问题。
身份验证呢? – Randnum
所以对我来说这将是System.setProperty(“http.proxy.mycompany.com”,“我的公司”); – Randnum
和System.setProperty(“http.8080”,“8080”);? – Randnum