Failed to connect to localhost/127.0.0.1:44393

In my code, the 'error message' part keeps returning as the response, and the try-catch section is not functioning.

TextView tv1;
@Override
protected void onCreate(Bundle savedInstanceState){ `This function is working`
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button b = (Button) findViewById(R.id.btn1);
    tv1 = (TextView) findViewById(R.id.txtview2);
    b.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            tv1.setText("sunucu cevabı");
            new arkaPlan().execute("https://localhost:44393/api/Arac");
        }

    });
}
//

package com.ilkdeneme.aracyakittakibi;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import java.net.NetPermission;
import java.security.Permission;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class MainActivity extends AppCompatActivity {

    TextView tv1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button b = (Button) findViewById(R.id.btn1);
        tv1 = (TextView) findViewById(R.id.txtview2);
        b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tv1.setText("sunucu cevabı");
                new arkaPlan().execute("https://localhost:44393/api/Arac");
            }

        });
    }
    //

    class arkaPlan extends AsyncTask<String,String,String> {
        @Override
        protected String doInBackground(String ... params) {

            HttpURLConnection connection = null;
            BufferedReader br = null;
            try {
                URL url = new URL(params[0]);
                connection = (HttpURLConnection) url.openConnection();
                connection.setRequestMethod("GET");
                connection.connect();
                InputStream is = connection.getInputStream();
                br = new BufferedReader(new InputStreamReader(is));
                String satir= "";
                String dosya = "";
                while ((satir = br.readLine()) != null) {
                    Log.d("satir:", satir);
                    dosya += satir;
                }
                Log.d("dosya:", dosya);
                return dosya;

            } catch (Exception e) {
              e.printStackTrace();

            }
            return "hata mesajı";

        }
        protected void onPostExecute(String s){
            Log.d("postExecutetangelen", s);
            tv1.setText(s.toString());
        }
    }

}

The error I got.

I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
W/System.err: java.net.ConnectException: Failed to connect to localhost/127.0.0.1:44393
W/System.err:     at com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:1417)
W/System.err:     at com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:1367)
W/System.err:     at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:219)
W/System.err:     at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:142)
W/System.err:     at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:104)
W/System.err:     at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:392)
W/System.err:     at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:325)
W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:489)
W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:131)
W/System.err:     at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:89)
W/System.err:     at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.connect(Unknown Source:0)
W/System.err:     at com.ilkdeneme.aracyakittakibi.MainActivity$arkaPlan.doInBackground(MainActivity.java:51)
W/System.err:     at com.ilkdeneme.aracyakittakibi.MainActivity$arkaPlan.doInBackground(MainActivity.java:41)
W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:333)
W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
W/System.err:     at java.lang.Thread.run(Thread.java:764)


Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation