Android アプリケーションから、Web サービスを呼び出してデータを取得する必要があります。その Web サービスを呼び出すには、HttpPost
エンティティを使用します。
問題は、次のエラーが発生することです。
11-18 15:57:42.807: I/ActivityThread(151): finish dispatching broadcast to com.android.server.PowerManagerService$BatteryReceiver@2ffcad08
11-18 15:57:42.807: I/ActivityThread(151): Dispatching broadcast android.intent.action.BATTERY_CHANGED to com.android.internal.policy.impl.KeyguardUpdateMonitor$3@2ff76710
11-18 15:57:42.807: I/ActivityThread(151): mRegistered=true mCurOrdered=false
11-18 15:57:42.807: I/ActivityThread(151): finish dispatching broadcast to com.android.internal.policy.impl.KeyguardUpdateMonitor$3@2ff76710
11-18 15:57:42.807: I/ActivityThread(151): Dispatching broadcast android.intent.action.BATTERY_CHANGED to com.android.server.connectivity.Tethering$StateReceiver@3002cf58
11-18 15:57:55.207: W/System.err(2327): java.net.SocketException: Connection reset by peer
11-18 15:57:55.217: W/System.err(2327): at org.apache.harmony.luni.platform.OSNetworkSystem.readSocketImpl(Native Method)
11-18 15:57:55.257: W/System.err(2327): at org.apache.harmony.luni.platform.OSNetworkSystem.read(OSNetworkSystem.java:358)
11-18 15:57:55.257: W/System.err(2327): at org.apache.harmony.luni.net.PlainSocketImpl.read(PlainSocketImpl.java:561)
11-18 15:57:55.257: W/System.err(2327): at org.apache.harmony.luni.net.SocketInputStream.read(SocketInputStream.java:88)
11-18 15:57:55.257: W/System.err(2327): at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:103)
11-18 15:57:55.257: W/System.err(2327): at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:191)
11-18 15:57:55.257: W/System.err(2327): at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:82)
11-18 15:57:55.267: W/System.err(2327): at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:174)
11-18 15:57:55.267: W/System.err(2327): at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:179)
11-18 15:57:55.277: W/System.err(2327): at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:235)
11-18 15:57:55.277: W/System.err(2327): at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:259)
11-18 15:57:55.277: W/System.err(2327): at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:279)
11-18 15:57:55.287: W/System.err(2327): at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:121)
11-18 15:57:55.287: W/System.err(2327): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:410)
11-18 15:57:55.297: W/System.err(2327): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
11-18 15:57:55.297: W/System.err(2327): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
11-18 15:57:55.307: W/System.err(2327): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
11-18 15:57:55.307: W/System.err(2327): at SplashScreen.sendJsonauthRegisterSession(SplashScreen.java:241)
11-18 15:57:55.317: W/System.err(2327): at $SplashScreenTask.doInBackground(SplashScreen.java:587)
11-18 15:57:55.317: W/System.err(2327): at android.os.AsyncTask$2.call(AsyncTask.java:185)
11-18 15:57:55.337: I/ActivityThread(240): Dispatching broadcast android.intent.action.SERVICE_STATE to com.android.phone.PhoneApp$PhoneAppBroadcastReceiver@2fe4b590
11-18 15:57:55.337: I/ActivityThread(240): mRegistered=true mCurOrdered=false
11-18 15:57:55.337: I/ActivityThread(240): finish dispatching broadcast to com.android.phone.PhoneApp$PhoneAppBroadcastReceiver@2fe4b590
11-18 15:57:55.347: I/ActivityThread(151): Dispatching broadcast android.intent.action.SERVICE_STATE to android.net.MobileDataStateTracker$MobileDataStateReceiver@3002b098
11-18 15:57:55.347: I/ActivityThread(247): enter process activity msg = 113
11-18 15:57:55.357: I/ActivityThread(151): mRegistered=true mCurOrdered=false
11-18 15:57:55.357: W/System.err(2327): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11-18 15:57:55.357: I/ActivityThread(151): finish dispatching broadcast to android.net.MobileDataStateTracker$MobileDataStateReceiver@3002b098
11-18 15:57:55.357: I/ActivityThread(151): Dispatching broadcast android.intent.action.ANY_DATA_STATE to android.net.MobileDataStateTracker$MobileDataStateReceiver@30023718
11-18 15:57:55.367: I/ActivityThread(151): mRegistered=true mCurOrdered=false
11-18 15:57:55.367: I/ActivityThread(151): finish dispatching broadcast to android.net.MobileDataStateTracker$MobileDataStateReceiver@30023718
11-18 15:57:55.367: I/ActivityThread(151): Dispatching broadcast android.intent.action.ANY_DATA_STATE to android.net.MobileDataStateTracker$MobileDataStateReceiver@30023f48
11-18 15:57:55.367: I/ActivityThread(151): mRegistered=true mCurOrdered=false
11-18 15:57:55.367: I/ActivityThread(151): finish dispatching broadcast to android.net.MobileDataStateTracker$MobileDataStateReceiver@30023f48
11-18 15:57:55.367: I/ActivityThread(151): Dispatching broadcast android.intent.action.ANY_DATA_STATE to android.net.MobileDataStateTracker$MobileDataStateReceiver@30024420
11-18 15:57:55.367: I/ActivityThread(151): mRegistered=true mCurOrdered=false
11-18 15:57:55.367: I/ActivityThread(240): Dispatching broadcast android.intent.action.ANY_DATA_STATE to com.android.phone.PhoneApp$PhoneAppBroadcastReceiver@2fe4b590
11-18 15:57:55.367: I/ActivityThread(240): mRegistered=true mCurOrdered=false
11-18 15:57:55.367: I/ActivityThread(240): finish dispatching broadcast to com.android.phone.PhoneApp$PhoneAppBroadcastReceiver@2fe4b590
11-18 15:57:55.377: I/ActivityThread(151): finish dispatching broadcast to android.net.MobileDataStateTracker$MobileDataStateReceiver@30024420
11-18 15:57:55.377: I/ActivityThread(151): Dispatching broadcast android.intent.action.ANY_DATA_STATE to android.net.MobileDataStateTracker$MobileDataStateReceiver@300248f8
11-18 15:57:55.377: I/ActivityThread(151): mRegistered=true mCurOrdered=false
11-18 15:57:55.377: I/ActivityThread(151): finish dispatching broadcast to android.net.MobileDataStateTracker$MobileDataStateReceiver@300248f8
11-18 15:57:55.377: I/ActivityThread(151): Dispatching broadcast android.intent.action.ANY_DATA_STATE to android.net.MobileDataStateTracker$MobileDataStateReceiver@3002b098
11-18 15:57:55.377: I/ActivityThread(151): mRegistered=true mCurOrdered=false
11-18 15:57:55.387: W/System.err(2327): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-18 15:57:55.387: I/ActivityThread(247): exit process activity msg = 113
11-18 15:57:55.397: W/System.err(2327): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
11-18 15:57:55.397: I/ActivityThread(151): finish dispatching broadcast to android.net.MobileDataStateTracker$MobileDataStateReceiver@3002b098
11-18 15:57:55.427: W/System.err(2327): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
11-18 15:57:55.427: W/System.err(2327): at java.lang.Thread.run(Thread.java:1096)
エラーは、この行の次のメソッドにあります。
response = client.execute(post);
public boolean sendJsonauthRegisterSession(JSONObject json, String url) {
HttpParams httpParameters = new BasicHttpParams();
int timeoutConnection = 150000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
int timeoutSocket = 150000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
DefaultHttpClient client = new DefaultHttpClient(httpParameters);
HttpResponse response;
try {
HttpPost post = new HttpPost(url);
JSONObject js = new JSONObject();
js.put("request_object", json);
StringEntity se = new StringEntity(js.toString());
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE,
"application/json"));
post.setEntity(se);
response = client.execute(post);
/* Checking response */
if (response != null) {
...
}
}
catch(UnknownHostException e5){
e5.printStackTrace();
this.callRegister="register_failed";
}
catch(SocketException ex) {
ex.printStackTrace();
this.callRegister="register_failed";
}
catch (Exception e) {
e.printStackTrace();
this.callRegister="register_failed";
}
client.getConnectionManager().shutdown();
return registersession;
}
メソッドは から呼び出されAsyncTask
ます。
私が間違っていることについて何か考えている人はいますか?ありがとうございました!!!
重要サーバーへの接続は 3G、EDGE で行われるため、非常に低速です。