gpt4 book ai didi

java - 连接拒绝异常

转载 作者:行者123 更新时间:2023-12-01 15:18:30 24 4
gpt4 key购买 nike

我收到此异常:

org.apache.http.conn.HttpHostConnectException: Connection to http://www.google.es refused
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:158)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:121)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:561)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:415)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
at sdf.main(sdf.java:17)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:123)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:148)
... 8 more

我正在运行的代码是这样的:

public class sdf {

static String url = "http://www.google.es";

public static void main(String[] args) {

try {
BufferedReader br = new BufferedReader(new InputStreamReader(
new DefaultHttpClient().execute(new HttpGet(url))
.getEntity().getContent()));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

无论 url 的值是多少,都不起作用。

我做错了什么?

最佳答案

您的 list 是否获得了正确的许可?这是您必须执行的示例:

<manifest xlmns:android...>
...
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>

没有这个,您将无法连接互联网

关于java - 连接拒绝异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11306795/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com