gpt4 book ai didi

java - 如何修复此 UnknownHostException?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:54:53 29 4
gpt4 key购买 nike

public static final String readURL(String url)throws Throwable
{
try {
InputStream in = (InputStream) fetch(url);
byte[] bArr = readBytes(in);
return new String(bArr);
} catch (Throwable e) {
throw e;
}
}


public static final Object fetch(String address) throws MalformedURLException,IOException {
URL url = new URL(address);
Object content = url.getContent();
return content;
}

我在代理后面,当我尝试时

readURL("http://abc.com ")

访问 URL http://abc.com它抛出 java.net.UnknownHostException:我有:

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

在 list 文件中。

有什么快速解决方案吗?

最佳答案

Proxy proxy = new Proxy(Proxy.DIRECT,
new InetSocketAddress(proxyHost, proxyPort));
url.openConnection(proxy);

System.setProperty("http.proxyHost", "my.proxyhost.com");
System.setProperty("http.proxyPort", "1234");

关于java - 如何修复此 UnknownHostException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1838140/

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