title: Android Https OAuth 401 Unauthorized error
body: <pre><code>private void login() {
              androidID = Secure.getString(MainActivity.this.getContentResolver(), Secure.ANDROID_ID);
              String uP = androidID.concat(":ClientTrustedSecret");
              byte[] authByteAry = null;
              try {
                      authByteAry = uP.getBytes("UTF-8");
              } catch (UnsupportedEncodingException e1) {
                      e1.printStackTrace();
              }
              String base64 = Base64.encodeToString(authByteAry, Base64.DEFAULT).trim();
              client.addHeader("Authorization", "Basic ".concat(base64));
              // Following format is required to post to OAuth
              JSONObject jsonObject = new JSONObject();
              try {
                      jsonObject.put("grant_type", "password");
                      jsonObject.put("username", "abc");
                      jsonObject.put("password", "abc");
              } catch (JSONException e1) {
                      e1.printStackTrace();
              }
              String contentType = "application/json; charset=UTF-8";
              StringEntity data = null;
              try {
                      // Send the json to the server
                      data = new StringEntity(jsonObject.toString());
                      client.post(MainActivity.this, baseURL.concat("/tokens"), data, contentType, new AsyncHttpResponseHandler() {
                              @Override
                              public void onSuccess(String response) {
                                      try {
                                              JSONObject jsonObject = new JSONObject(response);
                                              oauthAccessTokenString = jsonObject.get("access_token").toString();
                                      } catch (JSONException e) {
                                              e.printStackTrace();
                                      }
                              }
                              @Override
                              public void onFailure(Throwable t, String err) {
                                      System.out.println("login failed");
                              }
                      });
              } catch (UnsupportedEncodingException e) {
                      e.printStackTrace();
              }
      }
  </code></pre>
  
  <p>The above is how I login. And when making another web serivce call I get the unauthorized. The unlock method requires the following headers.</p>
  
  <p><a href="http://i.imgur.com/EaWDO.png" rel="nofollow">http://i.imgur.com/EaWDO.png</a></p>
  
  <pre><code>private void unlock()
      {
              AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
              asyncHttpClient.addHeader("Locale", "en_US");
              asyncHttpClient.addHeader("X-Originator-Type", "app");
              asyncHttpClient.addHeader("Content-Type", "application/json");
  //              asyncHttpClient.addHeader("Connection", "Keep-Alive");
  //              asyncHttpClient.addHeader("X-Device-Id", androidID);
  //              asyncHttpClient.addHeader("X-via", deviceId);
  //              asyncHttpClient.addHeader("ClientID", "abc@abc.com");
              asyncHttpClient.addHeader("Authorization", "Bearer ".concat(oauthAccessTokenString));
              asyncHttpClient.get("host/users?loginName=abc@abc.com", new AsyncHttpResponseHandler() {
                  @Override
                  public void onSuccess(String response) {
                      System.out.println(response);
                  }
                  @Override
                      public void onFailure(Throwable t, String err) {
                              System.out.println("Unlock server call failed");
                              Log.d("printing error: ", err);
                      }
              });
      }
  </code></pre>
  
  <p>Above code throws 401 unauthorized exception. No references in documentation which I have, to call back url. I am providing the oauth access token just fine, but then why is it that I still get 401? Does the secret has anything to do with the second call? I am told is that I need to set up my headers that way. I am also told that "For https, the client needs to be able to handle the validation of the certificate. Does anyone knows how to solve it?</p>