title: Why do I keep getting 404 errors when I retrieve https data through OkHttpClient
body: <p>I'm sure the URL is correct.
  <a href="https://openapi.taifex.com.tw/v1/DailyForeignExchangeRates" rel="nofollow noreferrer">https://openapi.taifex.com.tw/v1/DailyForeignExchangeRates</a></p>
  <p>When I browse it directly through Chrome, I get the file below</p>
  <p><a href="https://i.stack.imgur.com/BmgJq.png" rel="nofollow noreferrer">enter image description here</a></p>
  <p>I checked the URL through Chrome and made sure that the GET method was used, as shown below</p>
  <p><a href="https://i.stack.imgur.com/hlrCp.png" rel="nofollow noreferrer">enter image description here</a></p>
  <p>But when I try to use OkHttpClient to fetch data in Android studio,
  I always get a 404 reply, I don't know why.</p>
  <p>404 message</p>
  <p><a href="https://i.stack.imgur.com/8UlpM.png" rel="nofollow noreferrer">enter image description here</a></p>
  <p>Below is my complete code.</p>
  <p>[APIActivity.java]</p>
  <pre class="lang-java prettyprint-override"><code>package com.weberhwang.testfirebase;
  
  import androidx.appcompat.app.AppCompatActivity;
  
  import android.os.Bundle;
  import android.util.Log;
  
  import java.io.IOException;
  import java.security.cert.CertificateException;
  import java.security.cert.X509Certificate;
  
  import javax.net.ssl.HostnameVerifier;
  import javax.net.ssl.SSLContext;
  import javax.net.ssl.SSLSession;
  import javax.net.ssl.SSLSocketFactory;
  import javax.net.ssl.TrustManager;
  import javax.net.ssl.X509TrustManager;
  
  import okhttp3.Call;
  import okhttp3.Callback;
  import okhttp3.OkHttpClient;
  import okhttp3.Request;
  import okhttp3.Response;
  
  public class APIActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_apiactivity);
          catchData();
      }
  
      private void catchData() {
          String address = &quot;https://openapi.taifex.com.tw/v1/DailyForeignExchangeRates&quot;;
  
          new Thread(() -&gt; {
              try {
                  OkHttpClient client = getUnsafeOkHttpClient();
                  Request request = new Request.Builder().url(address).build();
                  Call call = client.newCall(request);
                  call.enqueue(new Callback() {
                      @Override
                      public void onFailure(Call call, IOException e) {
                          Log.d(&quot;MyLog&quot;, &quot;Exception&quot;, e);
                      }
  
                      @Override
                      public void onResponse(Call call, Response response) throws IOException {
                          Log.d(&quot;MyLog&quot;, response.body().string());
                      }
                  });
              } catch (Exception e) {
                  Log.d(&quot;MyLog&quot;, &quot;Exception&quot;, e);
              }
          }).start();
      }
  
      private OkHttpClient getUnsafeOkHttpClient() {
          try {
              // Create a trust manager that does not validate certificate chains
              final TrustManager[] trustAllCerts = new TrustManager[]{
                      new X509TrustManager() {
                          @Override
                          public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
                          }
  
                          @Override
                          public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
                          }
  
                          @Override
                          public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                              return new java.security.cert.X509Certificate[0];
                          }
                      }
              };
  
              final X509TrustManager trustManager = new X509TrustManager() {
                  @Override
                  public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                  }
  
                  @Override
                  public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                  }
  
                  @Override
                  public X509Certificate[] getAcceptedIssuers() {
                      return new X509Certificate[0];
                  }
              };
  
  
              // Install the all-trusting trust manager
              final SSLContext sslContext = SSLContext.getInstance(&quot;SSL&quot;);
              sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
              // Create an ssl socket factory with our all-trusting manager
              final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
  
              HostnameVerifier verifier = new HostnameVerifier() {
                  @Override
                  public boolean verify(String hostname, SSLSession session) {
                      return true;
                  }
              };
              return new OkHttpClient.Builder()
                      .sslSocketFactory(sslContext.getSocketFactory(), trustManager)
                      .hostnameVerifier(verifier)
                      .build();
          } catch (Exception e) {
              throw new RuntimeException(e);
          }
      }
  }
  </code></pre>
  <p>[AndroidManifest.xml]</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      package=&quot;com.weberhwang.testfirebase&quot;&gt;
  
      &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot; /&gt;
  
      &lt;application
          android:allowBackup=&quot;true&quot;
          android:icon=&quot;@mipmap/ic_launcher&quot;
          android:label=&quot;@string/app_name&quot;
          android:roundIcon=&quot;@mipmap/ic_launcher_round&quot;
          android:supportsRtl=&quot;true&quot;
          android:theme=&quot;@style/Theme.TestFireBase&quot;
          android:usesCleartextTraffic=&quot;true&quot;&gt;
          &lt;activity
              android:name=&quot;.APIActivity&quot;
              android:exported=&quot;true&quot;&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
  
                  &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;!-- &lt;meta-data --&gt;
          &lt;!-- android:name=&quot;com.google.android.actions&quot; --&gt;
          &lt;!-- android:resource=&quot;@xml/network_security_config&quot; /&gt; --&gt;
          &lt;activity
              android:name=&quot;.MainActivity&quot;
              android:exported=&quot;true&quot;&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
  
                  &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>