title: Making a retrofit request returns a response code 401 from server and Trust anchor for certification path not found for local host
body: <p>I am working on a app that gets data from a WebService written by my co-worker. When I make a call to get a token string, it works. When call to get different data, it returns a 401 response. If I run the WebService locally, I get the following error.
  Message:java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.. stack:kotlin.Unit, call:retrofit2.DefaultCallAdapterFactory$ExecutorCallbackCall@cc5eb95
  It looks like I need to install some kind of certificate on my local machine, but I have no clue what to install and where to install.
  Also, how to resolve the 401 response.</p>
  <pre><code>            val client = OkHttpClient.Builder()
              .addInterceptor(ApiInterceptor())
              //.addInterceptor(BasicAuthInterceptor(username, password)) //not needed in the url.
              .build()
  
          val gson = GsonBuilder()
              .setLenient()
              .create();
  
          val retro = Retrofit.Builder()
              .baseUrl(Constants.URL_MYAPP_API)
              .client(client)
              .addConverterFactory(GsonConverterFactory.create(gson))
              //.addConverterFactory(MoshiConverterFactory.create())
              .build()
  
          val service = retro.create(UserInfoService::class.java)    // location of the service file
          val UserInfoRequest = service.getUserInfoList()               // get token by calling api in the service file
          UserInfoRequest.enqueue(object : Callback&lt;List&lt;UserInfo&gt;&gt; {
  
              override fun onResponse(call: Call&lt;List&lt;UserInfo&gt;&gt;, response: Response&lt;List&lt;UserInfo&gt;&gt;) {
                  Log.i(Constants.LOG_TAG, &quot;Response.code(): ${response.code()}&quot;)
                  if (response.code() == 200) {
                      list = response.body()
                      Log.i(Constants.LOG_TAG, &quot;******* response.code = 200&quot;)
                      insert(list)
                      Log.i(Constants.LOG_TAG,
                          &quot;******* Done inserting data in UserInfor data ${response.code()}&quot;)
                  }
                  else
                  {
                      Log.i(Constants.LOG_TAG,&quot;******* User UserInfoViewModel Failure. Response code is ${response.code()}&quot;)
                  }
                  Log.i(Constants.LOG_TAG,
                      &quot;After getting response&quot;)
              }
  
              override fun onFailure(call: Call&lt;List&lt;UserInfo&gt;&gt;, t: Throwable) {
                  Log.i(Constants.LOG_TAG,
                      &quot;*** FAILURE: Error making request!!!.\nMessage:${t.message}. stack:${t.printStackTrace()}, call:${call}&quot;)
              }
          })
      } catch (e: Exception) {
          Log.i(Constants.LOG_TAG, &quot;Failure: ${e.message} - Error making request!!!&quot;)
      }
  
  const val URL_USERINFO_API = &quot;https://addressApp.myCompany.com/AddressAPI/&quot; //Server address
  </code></pre>
  <p>@GET(&quot;api/User/details/John/Doe&quot;)
  fun getUserList(): Call&lt;List&gt;</p>
  <p>I cannot include the name and type of the applicaton, so I have put UserInfo etc.</p>