我尝试使用该格式从我的应用程序向我的计算机发出请求
my_ip:8888/msg/my_message
当我打开连接时,它可以工作,但执行永远不会超过执行(请求)部分。它在执行get请求之前超时(1分钟到)。请求网址是正确的,因为我已经直接在我的电脑浏览器上试过了。
我的Android清单有互联网权限。
这是代码
private static JSONObject sendPetition(HttpUriRequest request) throws Exception{
AndroidHttpClient client;
HttpResponse response;
JSONObject responseJSON;
client = AndroidHttpClient.newInstance("IPM-HttpClient/UNAVAILABLE");
response= client.execute(request);
responseJSON = new JSONObject(EntityUtils.toString(response.getEntity()));
client.close();
return responseJSON;
}
编辑1:
好像我还没有给出足够的信息。抱歉:这是日志
11-29 12:10:21.503 5546-5546 / com.example.alvarofeal.aplicacioncliente I / View:点击调度到android.widget.Button {41f3ede0 VFED..C。 ... P .... 311,754-407,826#7f080002 app:id / button},event = MotionEvent {action = ACTION_UP,id [0] = 0,x [0] = 59.31427,y [0] = 32.06659,toolType [0] = TOOL_TYPE_FINGER,buttonState = 0,metaState = 0,flags = 0x0,edgeFlags = 0x0,pointerCount = 1,historySize = 0,eventTime = 2125112,downTime = 2124997,deviceId = 4,source = 0x1002}
11-29 12:10:21.504 5546-5546 / com.example.alvarofeal.aplicacioncliente V / Provider / Settings:from settings cache,name = sound_effects_enabled,value = 0
11-29 12:10:21.506 5546-5546 / com.example.alvarofeal.aplicacioncliente D / dalvikvm:create interp thread:stack size = 128KB
11-29 12:10:21.506 5546-5546 / com.example.alvarofeal.aplicacioncliente D / dalvikvm:创建新线程
11-29 12:10:21.507 5546-5546 / com.example.alvarofeal.aplicacioncliente D / dalvikvm:新线程已创建
11-29 12:10:21.507 5546-5546 / com.example.alvarofeal.aplicacioncliente D / dalvikvm:更新主题列表
11-29 12:10:21.507 5546-5669 / com.example.alvarofeal.aplicacioncliente D / dalvikvm:threadid = 12:interp stack at 0x6126a000
11-29 12:10:21.507 5546-5669 / com.example.alvarofeal.aplicacioncliente D / dalvikvm:threadid = 12:从interp创建
11-29 12:10:21.507 5546-5546 / com.example.alvarofeal.aplicacioncliente D / dalvikvm:开始新线程
11-29 12:10:21.507 5546-5669 / com.example.alvarofeal.aplicacioncliente D / dalvikvm:threadid = 12:notify debugger
11-29 12:10:21.507 5546-5669 / com.example.alvarofeal.aplicacioncliente D / dalvikvm:threadid = 12(AsyncTask#1):调用run()
11-29 12:10:21.509 5546-5669 / com.example.alvarofeal.aplicacioncliente I / System.out:httget:http:// 192.168.0.8:8888/msg/play/eABHFSQKCdU
11-29 12:10:21.512 5546-5669 / com.example.alvarofeal.aplicacioncliente I / System.out:http:// 192.168.0.8:8888/msg/play/eABHFSQKCdU
11-29 12:10:21.519 5546-5669 / com.example.alvarofeal.aplicacioncliente D / dalvikvm:create interp thread:stack size = 128KB
11-29 12:10:21.519 5546-5669 / com.example.alvarofeal.aplicacioncliente D / dalvikvm:创建新线程
11-29 12:10:21.519 5546-5669 / com.example.alvarofeal.aplicacioncliente D / dalvikvm:新线程已创建
11-29 12:10:21.519 5546-5669 / com.example.alvarofeal.aplicacioncliente D / dalvikvm:更新主题列表
11-29 12:10:21.519 5546-5670 / com.example.alvarofeal.aplicacioncliente D / dalvikvm:threadid = 13:interp stack at 0x6138a000
11-29 12:10:21.519 5546-5670 / com.example.alvarofeal.aplicacioncliente D / dalvikvm:threadid = 13:从interp创建
11-29 12:10:21.519 5546-5669 / com.example.alvarofeal.aplicacioncliente D / dalvikvm:开始新线程
11-29 12:10:21.520 5546-5670 / com.example.alvarofeal.aplicacioncliente D / dalvikvm:threadid = 13:notify debugger
11-29 12:10:21.520 5546-5670 / com.example.alvarofeal.aplicacioncliente D / dalvikvm:threadid = 13(RefQueueWorker @ org.apache.http.impl.conn.tsccm.ConnPoolByRoute @ 41fae950):call run()的
11-29 12:10:21.533 5546-5669 / com.example.alvarofeal.aplicacioncliente I / System.out:[socket] [0] connection /192.168.0.8:8888;LocalPort=34838(60000)
11-29 12:10:21.533 5546-5669 / com.example.alvarofeal.aplicacioncliente I / System.out:[CDS] connect [/192.168.0.8:8888] tm:60
11-29 12:10:21.534 5546-5669 / com.example.alvarofeal.aplicacioncliente D / Posix:[Posix_connect Debug]处理com.example.alvarofeal.aplicacioncliente:8888
之后它只会抛出一个connectiontimeout异常:
EDIT3:
11-29 12:27:19.988 6207-6277 / com.example.alvarofeal.aplicacioncliente W / System.err:org.apache.http.conn.ConnectTimeoutException:连接到/192.168.0.8:8888超时
11-29 12:27:19.990 6207-6277 / com.example.alvarofeal.aplicacioncliente W / System.err:at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:121)< / p>
11-29 12:27:19.991 6207-6277 / com.example.alvarofeal.aplicacioncliente W / System.err:at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)< / p>
11-29 12:27:19.992 6207-6277 / com.example.alvarofeal.aplicacioncliente W / System.err:at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)< / p>
11-29 12:27:19.992 6207-6277 / com.example.alvarofeal.aplicacioncliente W / System.err:at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)< / p>
11-29 12:27:19.993 6207-6277 / com.example.alvarofeal.aplicacioncliente W / System.err:at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:365)< / p>
11-29 12:27:19.994 6207-6277 / com.example.alvarofeal.aplicacioncliente W / System.err:at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:587)< / p>
11-29 12:27:19.995 6207-6277 / com.example.alvarofeal.aplicacioncliente W / System.err:at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:511)< / p>
11-29 12:27:19.996 6207-6277 / com.example.alvarofeal.aplicacioncliente W / System.err:at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:489)< / p>
11-29 12:27:19.996 6207-6277 / com.example.alvarofeal.aplicacioncliente W / System.err:at android.net.http.AndroidHttpClient.execute(AndroidHttpClient.java:260)
11-29 12:27:19.997 6207-6277 / com.example.alvarofeal.aplicacioncliente W / System.err:at com.example.alvarofeal.model.Model.sendPetition(Model.java:29)
11-29 12:27:19.998 6207-6277 / com.example.alvarofeal.aplicacioncliente W / System.err:at com.example.alvarofeal.model.Model.playVideo(Model.java:38)
11-29 12:27:19.999 6207-6277 / com.example.alvarofeal.aplicacioncliente W / System.err:at com.example.alvarofeal.aplicacioncliente.VideoList $ Videos.doInBackground(VideoList.java:170)< / p>
11-29 12:27:20.000 6207-6277 / com.example.alvarofeal.aplicacioncliente W / System.err:at com.example.alvarofeal.aplicacioncliente.VideoList $ Videos.doInBackground(VideoList.java:165)< / p>
11-29 12:27:20.003 6207-6277 / com.example.alvarofeal.aplicacioncliente W / System.err:at android.os.AsyncTask $ 2.call(AsyncTask.java:288)
11-29 12:27:20.005 6207-6277 / com.example.alvarofeal.aplicacioncliente W / System.err:at java.util.concurrent.FutureTask.run(FutureTask.java:237)
11-29 12:27:20.007 6207-6277 / com.example.alvarofeal.aplicacioncliente W / System.err:at android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:231)
11-29 12:27:20.009 6207-6277 / com.example.alvarofeal.aplicacioncliente W / System.err:at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
11-29 12:27:20.012 6207-6277 / com.example.alvarofeal.aplicacioncliente W / System.err:at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:587)<< >
11-29 12:27:20.013 6207-6277 / com.example.alvarofeal.aplicacioncliente W / System.err:at java.lang.Thread.run(Thread.java:841)
设定: 我正在使用我的Android设备而且我正在尝试与我的计算机通信(端口8888)。他们都在同一个网络中。
答案 0 :(得分:0)
我认为您应该为您的请求设置超时,如下所示:
private static JSONObject sendPetition(HttpUriRequest request) throws Exception{
AndroidHttpClient client;
int timeout = 5000
HttpResponse response;
JSONObject responseJSON;
client = AndroidHttpClient.newInstance("IPM-HttpClient/UNAVAILABLE");
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
HttpConnectionParams.setSoTimeout(httpParams, timeout);
request.setParams(httpParams);
response = client.execute(request);
responseJSON = new JSONObject(EntityUtils.toString(response.getEntity()));
client.close();
return responseJSON;
}