title: Login via Rest web service from android using retrofit not working
body: <p>I am making an android app using <strong>Retrofit 2</strong>. My REST Api are all written in Liferay. Now in Liferay, what I have seen is, to access the web services we need to authenticate first. So i have authenticated like this </p>
  
  <pre><code>http://test:q1w2e3r4@192.168.0.110:8080/liferay-portlet/api/secure/jsonws/
  </code></pre>
  
  <p>Liferay has its own user authentication method which we have overridden.I checked the Web service call from Postman its working fine.</p>
  
  <pre><code>URL:http://test:q1w2e3r4@192.168.0.110:8080/liferay-portlet/api/secure/jsonws/customuserauthentication/authenticate-by-user-name
  </code></pre>
  
  <p>form-encoded values</p>
  
  <pre><code>companyId:10154
  screenName:xyz
  password:xyz
  active:true
  </code></pre>
  
  <p>If i put this in the postman, it fetches the json response properly.</p>
  
  <p>Now when i call the same from my android code i get a response "Unauthorized".</p>
  
  <p>My Retrofit service</p>
  
  <pre><code>public interface LoginApi {    
      @FormUrlEncoded
      @POST("/liferay-portlet/api/secure/jsonws/customuserauthentication/authenticate-by-user-name")
      Call&lt;User&gt; login(@Field("companyId")long companyId,@Field("screenName")String screenName,@Field("password")String password,@Field("active")boolean active);
  }
  </code></pre>
  
  <p>My RestApiManager Class(This class is used to call the service interface and create the retrofit builder)</p>
  
  <pre><code>public class RestApiManager {
  
      private LoginApi loginApi;
  
      public LoginApi login() {
          if (loginApi==null) {
              GsonBuilder gson=new GsonBuilder();
              gson.registerTypeAdapter(String.class, new StringDeserializer());
              Retrofit retrofit=new Retrofit.Builder()
                  .baseUrl("http://test:q1w2e3r4@192.168.0.110:8080")
                  .addConverterFactory(GsonConverterFactory.create())
                  .build();
              loginApi=retrofit.create(LoginApi.class);
      }
      return loginApi;
  }
  </code></pre>
  
  <p>A call to the RestApiManager</p>
  
  <pre><code>Call&lt;User&gt; callUser=restApiManager.login().login(loginData.getCompanyId(),loginData.getScreenName(),loginData.getPassword(),loginData.isActive());
  callUser.enqueue(new Callback&lt;User&gt;() {
      @Override
      public void onResponse(Response&lt;User&gt; response, Retrofit retrofit) {
          Log.d("Login","Login Response:"+response.body());
      }
  
      @Override
      public void onFailure(Throwable t) {
          Log.d("Login","Login Response:"+t.getMessage());
      }
  });
  </code></pre>