title: Android studio - Localhost connection File not found?
body: <p>So I have been trying to make an authentication feature on my app where the users can login. I am trying to send JSON objects to my Django REST API so tha my users can get tokens. </p>
  
  <p>However, whenever after I press login with a valid user's credentials (me), my logcat throws a file not found exception to <code>http://192.168.0.18:8000/token-auth/</code> even if I can access it in my browser.</p>
  
  <p>I am running my Django REST API through XAMPP in my macbook pro. My Android emulator is running in my Desktop. I was able to similar thing with my ReactJS app in my macbook pro where I can retrieve data from my Django REST API.</p>
  
  <p>I already placed <code>&lt;uses-permission android:name="android.permission.INTERNET" /&gt;</code> in my manifest.xml and it took care of my permission issue.</p>
  
  <p>Below are my codes:</p>
  
  <p>login.java</p>
  
  <pre><code>public class Login extends AppCompatActivity {
  
      Button LoginButton;
      EditText uUserName, uPassWord;
      WSAdapter.SendAPIRequests AuthHelper;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_login);
  
          //SetupHomeBtn = (ImageButton) findViewById(R.id.SetupHomeBtn);
  
          LoginButton = (Button) findViewById(R.id.LoginButton);
  
          uUserName = (EditText) findViewById(R.id.LoginUserBox);
          uPassWord = (EditText) findViewById(R.id.LoginPassBox);
  
          //AuthHelper = new WSAdapter().new SendDeviceDetails();
  
          // Moves user to the main page after validation
          LoginButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  // gets the username and password from the EditText
                  String strUserName = uUserName.getText().toString();
                  String strPassWord = uPassWord.getText().toString();
  
                  // API url duh
                  String APIUrl = "http://192.168.0.18:8000/token-auth/";
  
                  // If the user is authenticated, then transfer to the MainActivity page
                  if (APIAuthentication(strUserName, strPassWord, APIUrl)){
                      startActivity(new Intent(Login.this, MainActivity.class));
                  }
              }
          });
  
      }
  
      private boolean APIAuthentication(String un, String pw, String url){
          // when it wasn't static -&gt; AuthHelper = new WSAdapter().new SendAPIRequests();
          AuthHelper = new WSAdapter.SendAPIRequests();
  
          JSONObject postData = new JSONObject();
          try {
              // Attempt to input info to the Django API
              postData.put("username", un);
              postData.put("password", pw);
  
              // Putting the data to be posted in the Django API
              AuthHelper.execute(url, postData.toString());
  
              return true;
          } catch (JSONException e) {
              e.printStackTrace();
          }
  
          return false;
      }
  }
  </code></pre>
  
  <p>WSAdapter.java</p>
  
  <pre><code>// I forgot what WS stands for, but this class serves as an adapter for JSON and Online stuff
  // I think it stands for With-Server Adapter
  public class WSAdapter extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
      }
  
      static public class SendAPIRequests extends AsyncTask&lt;String, Void, String&gt; {
  
          @Override
          protected String doInBackground(String... params) {
  
              Log.e("TAG", params[0]);
              Log.e("TAG", params[1]);
              String data = "";
  
              HttpURLConnection httpURLConnection = null;
              try {
  
                  // Sets up connection to the URL (params[0] from .execute in "login")
                  httpURLConnection = (HttpURLConnection) new URL(params[0]).openConnection();
  
                  // Sets the request method for the URL
                  httpURLConnection.setRequestMethod("POST");
  
                  // Tells the URL that I am sending a POST request body
                  httpURLConnection.setDoOutput(true);
  
                  // To write primitive Java data types to an output stream in a portable way
                  DataOutputStream wr = new DataOutputStream(httpURLConnection.getOutputStream());
                  // Writes out a byte to the underlying output stream of the data posted from .execute function
                  wr.writeBytes("postData=" + params[1]);
                  // Flushes the postData to the output stream
                  wr.flush();
                  wr.close();
  
                  // Representing the input stream
                  InputStream in = httpURLConnection.getInputStream();
  
                  // Preparing input stream bytes to be decoded to charset
                  InputStreamReader inputStreamReader = new InputStreamReader(in);
                  StringBuilder dataBuffer = new StringBuilder();
  
                  // Translates input stream bytes to charset
                  int inputStreamData = inputStreamReader.read();
                  while (inputStreamData != -1) {
                      char current = (char) inputStreamData;
                      inputStreamData = inputStreamReader.read();
                      // concatenates data characters from input stream
                      dataBuffer.append(current);
                  }
                  data = dataBuffer.toString();
              } catch (Exception e) {
                  e.printStackTrace();
              } finally {
                  // Disconnects socket after using
                  if (httpURLConnection != null) {
                      httpURLConnection.disconnect();
                  }
              }
  
              Log.e("TAG", data);
              return data;
          }
  
          @Override
          protected void onPostExecute(String result) {
              super.onPostExecute(result);
              // expecting a response code fro my server upon receiving the POST data
              Log.e("TAG", result);
          }
      }
  
  
  }
  </code></pre>
  
  <p>Below is my logcat regarding the issue:</p>
  
  <pre><code>12-28 00:57:13.659 9025-9057/com.example.android.androidcraftsappprototype E/TAG: http://192.168.0.18:8000/token-auth/
      {"username":"erichardson","password":"ellyrichardson"}
  12-28 00:57:13.743 9025-9057/com.example.android.androidcraftsappprototype D/NetworkSecurityConfig: No Network Security Config specified, using platform default
  12-28 00:57:13.990 9025-9051/com.example.android.androidcraftsappprototype D/EGL_emulation: eglMakeCurrent: 0xa0f86f00: ver 2 0 (tinfo 0xa8d9b540)
  12-28 00:57:14.038 9025-9051/com.example.android.androidcraftsappprototype D/EGL_emulation: eglMakeCurrent: 0xa0f86f00: ver 2 0 (tinfo 0xa8d9b540)
  12-28 00:57:14.039 9025-9057/com.example.android.androidcraftsappprototype W/System.err: java.io.FileNotFoundException: http://192.168.0.18:8000/token-auth/
  12-28 00:57:14.040 9025-9057/com.example.android.androidcraftsappprototype W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:251)
          at com.example.android.androidcraftsappprototype.WSAdapter$SendAPIRequests.doInBackground(WSAdapter.java:56)
          at com.example.android.androidcraftsappprototype.WSAdapter$SendAPIRequests.doInBackground(WSAdapter.java:26)
          at android.os.AsyncTask$2.call(AsyncTask.java:333)
          at java.util.concurrent.FutureTask.run(FutureTask.java:266)
          at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
          at java.lang.Thread.run(Thread.java:764)
  12-28 00:57:14.118 9025-9051/com.example.android.androidcraftsappprototype D/EGL_emulation: eglMakeCurrent: 0xa0f86f00: ver 2 0 (tinfo 0xa8d9b540)
  12-28 00:57:14.176 9025-9051/com.example.android.androidcraftsappprototype D/EGL_emulation: eglMakeCurrent: 0xa0f86f00: ver 2 0 (tinfo 0xa8d9b540)
  12-28 00:57:14.198 9025-9051/com.example.android.androidcraftsappprototype D/EGL_emulation: eglMakeCurrent: 0xa0f86f00: ver 2 0 (tinfo 0xa8d9b540)
  12-28 00:57:14.209 9025-9051/com.example.android.androidcraftsappprototype D/OpenGLRenderer: endAllActiveAnimators on 0x8f1e9d00 (RippleDrawable) with handle 0x8eb4b900
  12-28 00:57:14.217 9025-9051/com.example.android.androidcraftsappprototype D/EGL_emulation: eglMakeCurrent: 0xa0f86f00: ver 2 0 (tinfo 0xa8d9b540)
  </code></pre>
  
  <p>I was expecting it to be able to connect, but for some reason it doesn't and I don't know why.</p>
  
  <p>Below is my code for the token authentication API for Django REST. Its pretty simple as I am only putting the API authentication url in my urls.py</p>
  
  <p>urls.py</p>
  
  <pre><code>from django.contrib import admin
  from django.urls import path, include
  from rest_framework_jwt.views import obtain_jwt_token
  
  urlpatterns = [
      path('api/', include('projects.urls')),
      path('admin/', admin.site.urls),
      path('token-auth/', obtain_jwt_token),
  ]
  </code></pre>