gpt4 book ai didi

java - 检查网站是否在线

转载 作者:行者123 更新时间:2023-11-29 21:13:02 26 4
gpt4 key购买 nike

我正在尝试检查 website在线。我已经试过了:

    public static boolean checkisonline(String targetUrl) {

if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}

HttpURLConnection httpUrlConn;
try {
httpUrlConn = (HttpURLConnection) new URL(targetUrl)
.openConnection();

httpUrlConn.setRequestMethod("HEAD");

// Set timeouts in milliseconds
httpUrlConn.setConnectTimeout(30000);
httpUrlConn.setReadTimeout(30000);

// Print HTTP status code/message for your information.
System.out.println("Response Code: "
+ httpUrlConn.getResponseCode());
System.out.println("Response Message: "
+ httpUrlConn.getResponseMessage());

return (httpUrlConn.getResponseCode() == HttpURLConnection.HTTP_OK);
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
return false;
}
}

但我总是得到 Error: null在输出中,即使网站在线。

堆栈驱动程序:
03-05 14:51:30.931 8409-8460/de.treevo.app I/System.out﹕ Error: null
03-05 14:51:30.931 8409-8460/de.treevo.app W/System.err﹕ java.io.EOFException
03-05 14:51:30.931 8409-8460/de.treevo.app W/System.err﹕ at java.util.zip.GZIPInputStream.readFully(GZIPInputStream.java:202)
03-05 14:51:30.931 8409-8460/de.treevo.app W/System.err﹕ at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:98)
03-05 14:51:30.931 8409-8460/de.treevo.app W/System.err﹕ at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:81)
03-05 14:51:30.931 8409-8460/de.treevo.app W/System.err﹕ at com.android.okhttp.internal.http.HttpEngine.initContentStream(HttpEngine.java:468)
03-05 14:51:30.931 8409-8460/de.treevo.app W/System.err﹕ at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:666)
03-05 14:51:30.931 8409-8460/de.treevo.app W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:347)
03-05 14:51:30.931 8409-8460/de.treevo.app W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:296)
03-05 14:51:30.931 8409-8460/de.treevo.app W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:503)
03-05 14:51:30.931 8409-8460/de.treevo.app W/System.err﹕ at de.treevo.core.functions.checkisonline(functions.java:79)
03-05 14:51:30.941 8409-8460/de.treevo.app W/System.err﹕ at de.treevo.app.add_series$1.run(add_series.java:167)
03-05 14:51:30.941 8409-8460/de.treevo.app W/System.err﹕ at java.lang.Thread.run(Thread.java:841)

最佳答案

关于java - 检查网站是否在线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22199556/

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