android客户端打开后显示网络错误?
论坛安装好后,可以通过 http://192.168.3.4/Carbon 来访问。
我在系统设置里将客户端API域名和PC端主站域名都设置为 http://192.168.3.4/Carbon/
在android代码 APIAddress.java里设置如下:
String = + ; String = + ; String = + ;
打开android客户端后会显示网络错误,抓了这些日志:
09-09 15:04:36.672 3562-3627/com.lincanbin.carbonforum D/POST URL :: http://192.168.3.4/Carbon/page/1
09-09 15:04:36.692 3562-3627/com.lincanbin.carbonforum D/POST parameter: SKey=12450&STime=1473404676&SValue=9a387a67d756118cd9f55904e457aaa3
09-09 15:04:36.716 3562-3562/com.lincanbin.carbonforum D/libEGL: loaded /system/lib/egl/libEGL_tiantianVM.so
[ 09-09 15:04:36.740 3562: 3562 D/ ]
HostConnection, value 22468
[ 09-09 15:04:36.740 3562: 3562 D/ ]
OpenglPort, stream_port_num 22468
[ 09-09 15:04:36.740 3562: 3562 D/ ]
HostConnection::get() New Host Connection pid 3562, tid 3562, stream_port_num=22468
[ 09-09 15:04:36.740 3562: 3562 D/ ]
useHgsmi for host connection!!!
[ 09-09 15:04:36.740 3562: 3562 D/ ]
HostConnection::get() New Host Connection established 0xb93beee8, tid 3562
09-09 15:04:36.756 3562-3562/com.lincanbin.carbonforum D/libEGL: loaded /system/lib/egl/libGLESv1_CM_tiantianVM.so
09-09 15:04:36.756 3562-3562/com.lincanbin.carbonforum D/libEGL: loaded /system/lib/egl/libGLESv2_tiantianVM.so
09-09 15:04:36.768 3562-3562/com.lincanbin.carbonforum W/EGL_tiantianVM: eglSurfaceAttrib not implemented
09-09 15:04:36.772 3562-3562/com.lincanbin.carbonforum D/OpenGLRenderer: Enabling debug mode 0
09-09 15:05:01.804 3562-3627/com.lincanbin.carbonforum D/Post Error: No Network
09-09 15:05:01.804 3562-3627/com.lincanbin.carbonforum W/System.err: java.net.ProtocolException: content-length promised 67 bytes, but received 0
09-09 15:05:01.816 3562-3627/com.lincanbin.carbonforum W/System.err: at com.android.okhttp.internal.http.RetryableOutputStream.close(RetryableOutputStream.java:52)
09-09 15:05:01.820 3562-3627/com.lincanbin.carbonforum W/System.err: at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:636)
09-09 15:05:01.832 3562-3627/com.lincanbin.carbonforum W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:347)
09-09 15:05:01.832 3562-3627/com.lincanbin.carbonforum W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:296)
09-09 15:05:01.832 3562-3627/com.lincanbin.carbonforum W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:503)
09-09 15:05:01.832 3562-3627/com.lincanbin.carbonforum W/System.err: at com.lincanbin.carbonforum.util.HttpUtil.postRequest(HttpUtil.java:192)
09-09 15:05:01.832 3562-3627/com.lincanbin.carbonforum W/System.err: at com.lincanbin.carbonforum.IndexActivity$GetTopicsTask.doInBackground(IndexActivity.java:436)
09-09 15:05:01.832 3562-3627/com.lincanbin.carbonforum W/System.err: at com.lincanbin.carbonforum.IndexActivity$GetTopicsTask.doInBackground(IndexActivity.java:374)
09-09 15:05:01.840 3562-3627/com.lincanbin.carbonforum W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:288)
09-09 15:05:01.852 3562-3627/com.lincanbin.carbonforum W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
09-09 15:05:01.852 3562-3627/com.lincanbin.carbonforum W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
09-09 15:05:01.856 3562-3627/com.lincanbin.carbonforum W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
09-09 15:05:01.868 3562-3627/com.lincanbin.carbonforum W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
09-09 15:05:01.868 3562-3627/com.lincanbin.carbonforum W/System.err: at java.lang.Thread.run(Thread.java:841)
看了很久,不知是什么原因。看了别人的帖子,说是配置问题,但不知哪里有错。
回复#5 @lincanbin :
嗯。现在客户端启动后会提示“网络错误”,日志里提示发生了异常:
java.net.ProtocolException: content-length promised 67 bytes, but received 0
如果我将HttpUtil.java 里的这句注释掉:
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(parameterString.length()));
就不会有这个异常,但会发生另外一个异常,不知道这个和配置有没有关系?
回复#7 @lincanbin :
你指的响应报文在哪里看呢?
我在apache的access.log中看到这些:
192.168.3.4 - - [10/Sep/2016:10:46:45 +0800] "POST /Carbon/page/1 HTTP/1.1" 302 -
192.168.3.4 - - [10/Sep/2016:10:46:45 +0800] "GET /Carbon/ HTTP/1.1" 200 6170
192.168.3.4 - - [10/Sep/2016:10:48:11 +0800] "-" 408 -
以下是logcat的输出:
09-10 10:46:45.865 19517-19553/com.lincanbin.carbonforum D/POST URL :: http://192.168.3.4/Carbon/page/1
09-10 10:46:45.873 19517-19553/com.lincanbin.carbonforum D/POST parameter: SKey=12450&STime=1473475605&SValue=ca64ca860279d76a713a3c221cb96e1a
09-10 10:46:45.905 19517-19517/com.lincanbin.carbonforum D/libEGL: loaded /system/lib/egl/libEGL_tiantianVM.so
[ 09-10 10:46:45.905 19517:19517 D/ ]
HostConnection, value 22468
[ 09-10 10:46:45.905 19517:19517 D/ ]
OpenglPort, stream_port_num 22468
[ 09-10 10:46:45.905 19517:19517 D/ ]
HostConnection::get() New Host Connection pid 19517, tid 19517, stream_port_num=22468
[ 09-10 10:46:45.905 19517:19517 D/ ]
useHgsmi for host connection!!!
[ 09-10 10:46:45.905 19517:19517 D/ ]
HostConnection::get() New Host Connection established 0xb8302b40, tid 19517
09-10 10:46:45.909 19517-19517/com.lincanbin.carbonforum D/libEGL: loaded /system/lib/egl/libGLESv1_CM_tiantianVM.so
09-10 10:46:45.909 19517-19517/com.lincanbin.carbonforum D/libEGL: loaded /system/lib/egl/libGLESv2_tiantianVM.so
09-10 10:46:45.933 19517-19517/com.lincanbin.carbonforum W/EGL_tiantianVM: eglSurfaceAttrib not implemented
09-10 10:46:45.933 19517-19517/com.lincanbin.carbonforum D/OpenGLRenderer: Enabling debug mode 0
09-10 10:47:10.969 19517-19553/com.lincanbin.carbonforum D/Post Error: No Network
09-10 10:47:10.969 19517-19553/com.lincanbin.carbonforum W/System.err: java.net.ProtocolException: content-length promised 67 bytes, but received 0
09-10 10:47:10.969 19517-19553/com.lincanbin.carbonforum W/System.err: at com.android.okhttp.internal.http.RetryableOutputStream.close(RetryableOutputStream.java:52)
09-10 10:47:10.969 19517-19553/com.lincanbin.carbonforum W/System.err: at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:636)
09-10 10:47:10.969 19517-19553/com.lincanbin.carbonforum W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:347)
09-10 10:47:10.969 19517-19553/com.lincanbin.carbonforum W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:296)
09-10 10:47:10.969 19517-19553/com.lincanbin.carbonforum W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:503)
09-10 10:47:10.969 19517-19553/com.lincanbin.carbonforum W/System.err: at com.lincanbin.carbonforum.util.HttpUtil.postRequest(HttpUtil.java:192)
09-10 10:47:10.973 19517-19553/com.lincanbin.carbonforum W/System.err: at com.lincanbin.carbonforum.IndexActivity$GetTopicsTask.doInBackground(IndexActivity.java:436)
09-10 10:47:10.973 19517-19553/com.lincanbin.carbonforum W/System.err: at com.lincanbin.carbonforum.IndexActivity$GetTopicsTask.doInBackground(IndexActivity.java:374)
09-10 10:47:10.973 19517-19553/com.lincanbin.carbonforum W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:288)
09-10 10:47:10.973 19517-19553/com.lincanbin.carbonforum W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
09-10 10:47:10.973 19517-19553/com.lincanbin.carbonforum W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
09-10 10:47:10.973 19517-19553/com.lincanbin.carbonforum W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
09-10 10:47:10.973 19517-19553/com.lincanbin.carbonforum W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
09-10 10:47:10.973 19517-19553/com.lincanbin.carbonforum W/System.err: at java.lang.Thread.run(Thread.java:841)
09-10 10:48:28.569 19517-19523/com.lincanbin.carbonforum D/dalvikvm: GC_FOR_ALLOC freed 551K, 10% free 6089K/6712K, paused 4ms, total 5ms
登录后方可回帖
在android代码 APIAddress.java里设置如下: