gpt4 book ai didi

android - java.net.ConnectException : failed to connect to/103. XX.XX.38(端口 8080):连接失败:ECONNREFUSED(连接被拒绝)

转载 作者:太空狗 更新时间:2023-10-29 15:04:01 25 4
gpt4 key购买 nike

我是 android 世界的新手。我试图开发一个应用程序,我尝试从未知来源下载和安装 .apk。其实我这个.apk是放在Url地址http://103.XX.XX.38:8080/apk/HelloAndroid.apk的开发服务器上的.这个 url 是绝对正确的,因为当我通过 Firefox 检查它时,它显示了一个对话框来下载这个 .apk。现在我在我的 android 应用程序中使用了这个 url,其代码如下

    try {
System.out.println("first of nethod");
URL url = new URL("http://103.XX.XX.38:8080/apk/HelloAndroid.apk");
System.out.println("second of method");
System.out.println("1");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
System.out.println("2");
urlConnection.setRequestMethod("GET");
System.out.println("3");
urlConnection.setDoOutput(true);
System.out.println("4");
urlConnection.connect();
System.out.println("5");

File sdcard = Environment.getExternalStorageDirectory();
System.out.println("6");
File file = new File(sdcard, "filename.apk");
System.out.println("7");

FileOutputStream fileOutput = new FileOutputStream(file);
System.out.println("8");
InputStream inputStream = urlConnection.getInputStream();

byte[] buffer = new byte[1024];
int bufferLength = 0;

while ( (bufferLength = inputStream.read(buffer)) > 0 ) {
fileOutput.write(buffer, 0, bufferLength);
}
fileOutput.close();
// this.checkUnknownSourceEnability();
this.installApk();

} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

但是我得到了一个异常(exception)

       05-13 15:52:03.120: W/System.err(12368): java.net.ConnectException: failed to connect to /103.XX.XX.38 (port 8080): connect failed: ECONNREFUSED (Connection refused)
05-13 15:52:03.120: W/System.err(12368): at libcore.io.IoBridge.connect(IoBridge.java:114)
05-13 15:52:03.120: W/System.err(12368): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
05-13 15:52:03.120: W/System.err(12368): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
05-13 15:52:03.120: W/System.err(12368): at java.net.Socket.connect(Socket.java:842)
05-13 15:52:03.120: W/System.err(12368): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:77)
05-13 15:52:03.120: W/System.err(12368): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
05-13 15:52:03.120: W/System.err(12368): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
05-13 15:52:03.120: W/System.err(12368): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
05-13 15:52:03.120: W/System.err(12368): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
05-13 15:52:03.130: W/System.err(12368): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
05-13 15:52:03.130: W/System.err(12368): at libcore.net.http.HttpEngine.connect(HttpEngine.java:303)
05-13 15:52:03.130: W/System.err(12368): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
05-13 15:52:03.130: W/System.err(12368): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
05-13 15:52:03.130: W/System.err(12368): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
05-13 15:52:03.130: W/System.err(12368): at com.example.test.TestOne.Update(TestOne.java:136)
05-13 15:52:03.130: W/System.err(12368): at com.example.test.TestOne$1$1$1.doInBackground(TestOne.java:71)
05-13 15:52:03.130: W/System.err(12368): at com.example.test.TestOne$1$1$1.doInBackground(TestOne.java:1)
05-13 15:52:03.130: W/System.err(12368): at android.os.AsyncTask$2.call(AsyncTask.java:264)
05-13 15:52:03.130: W/System.err(12368): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
05-13 15:52:03.130: W/System.err(12368): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
05-13 15:52:03.130: W/System.err(12368): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
05-13 15:52:03.140: W/System.err(12368): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
05-13 15:52:03.140: W/System.err(12368): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
05-13 15:52:03.140: W/System.err(12368): at java.lang.Thread.run(Thread.java:856)
05-13 15:52:03.140: W/System.err(12368): Caused by: libcore.io.ErrnoException: connect failed: ECONNREFUSED (Connection refused)
05-13 15:52:03.140: W/System.err(12368): at libcore.io.Posix.connect(Native Method)
05-13 15:52:03.140: W/System.err(12368): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
05-13 15:52:03.140: W/System.err(12368): at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
05-13 15:52:03.140: W/System.err(12368): at libcore.io.IoBridge.connect(IoBridge.java:112)
05-13 15:52:03.140: W/System.err(12368): ... 23 more

在逐步调试之后,它会执行到

      urlConnection.setDoOutput(true);

我可能会遇到问题

      urlConnection.connect();

我正在使用真实设备 Sony Tablet S (4.0.3)。非常感谢任何帮助。在此先感谢大家

最佳答案

问题解决了愚蠢的问题。这是真实设备的网络可访问性问题。我的网络受 Cyber​​oam 保护,所以对于真实设备,当我使用 exception gone 时,我需要 Cyber​​oam 的凭证。

关于android - java.net.ConnectException : failed to connect to/103. XX.XX.38(端口 8080):连接失败:ECONNREFUSED(连接被拒绝),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23629127/

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