サーバに接続するときに「Connection refused」というエラーが表示されます。 ブラウザでURLを開くと正常に動作します。私のアプリはインターネット許可を持っています。 は、ここにスタックトレースです:Android:接続が拒否されたエラー
08-03 16:17:05.549 28233-28267/appname.myname.com.appname W/System: ClassLoader referenced unknown path: /data/data/appname.myname.com.appname/lib
08-03 16:17:07.336 28233-28321/appname.myname.com.appname W/System.err: java.net.ConnectException: Connection refused
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at java.net.PlainSocketImpl.socketConnect(Native Method)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:334)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:196)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:356)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at java.net.Socket.connect(Socket.java:586)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at com.android.okhttp.internal.Platform.connectSocket(Platform.java:113)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at com.android.okhttp.Connection.connectSocket(Connection.java:196)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at com.android.okhttp.Connection.connect(Connection.java:172)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:329)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:405)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:243)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at appname.myname.com.appname.Search$Async$override.doInBackground(Search.java:63)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at appname.myname.com.appname.Search$Async$override.access$dispatch(Search.java)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at appname.myname.com.appname.Search$Async.doInBackground(Search.java:0)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at appname.myname.com.appname.Search$Async.doInBackground(Search.java:50)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:304)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
08-03 16:17:07.338 28233-28321/appname.myname.com.appname W/System.err: at java.lang.Thread.run(Thread.java:761)
ここに私のクラスです:
public static class Async extends AsyncTask<String, Integer, String> {
@Override
protected String doInBackground(String... params) {
URL url = null;
try {
url = new URL("http://localhost:80/mysql/php.php");
}catch (MalformedURLException ex){
ex.printStackTrace();
}
try {
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
Log.d("dd", "e" + line);
}catch(IOException ex){
ex.printStackTrace();
}
return "";
}
}
はアプリの問題、あるいは私のサーバーですか?
HttpClientは廃止され、使用できません。これを行う別の方法はありませんか? – AlGrande