我正在使用改造2一個Android應用程序。我的REST API全部用Liferay編寫。現在在Liferay中,我看到的是訪問我們首先需要進行身份驗證的Web服務。所以我有驗證這樣登錄於Android使用改造工作不
http://test:[email protected]:8080/liferay-portlet/api/secure/jsonws/
Liferay的有,我們有overridden.I檢查從郵差Web服務調用它的做工精細自己的用戶身份驗證方法。
URL:http://test:[email protected]:8080/liferay-portlet/api/secure/jsonws/customuserauthentication/authenticate-by-user-name
形式編碼的值
companyId:10154
screenName:xyz
password:xyz
active:true
如果我把這個在郵遞員,它正確地取出JSON響應。
現在,當我打電話一樣從我的Android代碼我得到迴應「未授權」。
我的改造服務
public interface LoginApi {
@FormUrlEncoded
@POST("/liferay-portlet/api/secure/jsonws/customuserauthentication/authenticate-by-user-name")
Call<User> login(@Field("companyId")long companyId,@Field("screenName")String screenName,@Field("password")String password,@Field("active")boolean active);
}
我RestApiManager類(該類用來調用該服務的接口,並創建改進助洗劑)
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:[email protected]:8080")
.addConverterFactory(GsonConverterFactory.create())
.build();
loginApi=retrofit.create(LoginApi.class);
}
return loginApi;
}
到RestApiManager
Call<User> callUser=restApiManager.login().login(loginData.getCompanyId(),loginData.getScreenName(),loginData.getPassword(),loginData.isActive());
callUser.enqueue(new Callback<User>() {
@Override
public void onResponse(Response<User> response, Retrofit retrofit) {
Log.d("Login","Login Response:"+response.body());
}
@Override
public void onFailure(Throwable t) {
Log.d("Login","Login Response:"+t.getMessage());
}
});
的呼叫
迴應是什麼?哪個回調被稱爲? – Blackbelt
你應該放一個Loggin –