大家好,我正在使用改造库实现一个Android休息客户端。我还实现了一个API(使用laravel框架)。所以我用参数调用API(GET方法),但遗憾的是它不起作用..
这是我的帖子方法网址"http://androidxxxxx-xx/api/OneUser/Id"
当我在邮递员中测试这个网址时,它正常工作
例如:"http://androidxxxxx-xx/api/OneUser/001"
这是我的Inferface类代码:
public interface OneUserApi {
//oneUser
@GET("/api/OneUser/{UserId}")
Call<OneUserDetails> GetAllUserDetailss(@Path("UserId")String id);
// Call<AllUserDetails> GetAllUserDetailss();
}
这是我的buttoneven代码
oneuser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String UserId="001";
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Api_Url)
.addConverterFactory(GsonConverterFactory.create())
.build();
OneUserApi service = retrofit.create(OneUserApi.class);
Call<OneUserDetails> call = service.GetAllUserDetailss("001");
Log.d("onResponse", "There is uuyan error");
call.enqueue(new Callback<OneUserDetails>() {
@Override
public void onResponse(Call<OneUserDetails> call, retrofit2.Response<OneUserDetails> response) {
try {
Log.d("onResponse", "There rtutrutris an error");
// one_UserId = response.body().
// int clientId=response.body().getUserId();
String UserId,TokenType,ExpierTime,AccessToken,Create,Update;
// clientSecret = response.body().getAcessToken();
// Log.e("ss", clientSecret);
// String clientSecret;
// Log.d("onResponse", "There is anccccc error");
// for (int i = 0; i < one_UserId.size(); i++) {
UserId = response.body().getUserId();
TokenType = response.body().getTokenType();
ExpierTime = response.body().getAcessToken();
AccessToken =response.body().getExpiertime();
Create = response.body().getUpdatedAt();
Update =response.body().getCreatedAt();
Log.e("UserId", UserId);
Log.e("TokenType", TokenType);
Log.e("ExpierTime", ExpierTime);
Log.e("AccessToken", AccessToken);
Log.e("Create", Create);
Log.e("Update", Update);
// }
} catch (Exception e) {
Log.d("onResponse", "There is an error");
e.printStackTrace();
}
}
@Override
public void onFailure(Call<OneUserDetails> call, Throwable t) {
}
});
}
});
我在邮递员中传递此网址时的json数据 ( “http://androidxxxxx-xx/api/OneUser/001”)
{
"UserId": "001",
"TokenType": "dffdfdfd",
"Expiertime": "dffdfddf4",
"AcessToken": "fdljfhjdlnfdf",
"created_at": "2017-07-13 03:18:51",
"updated_at": "2017-07-13 03:18:51"
} ]
myOneUserDetails.java clas
public class OneUserDetails implements Serializable {
@SerializedName("UserId")
@Expose
private String userId;
@SerializedName("TokenType")
@Expose
private String tokenType;
@SerializedName("Expiertime")
@Expose
private String expiertime;
@SerializedName("AcessToken")
@Expose
private String acessToken;
@SerializedName("created_at")
@Expose
private String createdAt;
@SerializedName("updated_at")
@Expose
private String updatedAt;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getTokenType() {
return tokenType;
}
public void setTokenType(String tokenType) {
this.tokenType = tokenType;
}
public String getExpiertime() {
return expiertime;
}
public void setExpiertime(String expiertime) {
this.expiertime = expiertime;
}
public String getAcessToken() {
return acessToken;
}
public void setAcessToken(String acessToken) {
this.acessToken = acessToken;
}
public String getCreatedAt() {
return createdAt;
}
public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}
public String getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(String updatedAt) {
this.updatedAt = updatedAt;
}
}
答案 0 :(得分:1)
您应该通过将{id}添加到GET请求
来将id指定为参数 @GET("api/OneUser/{id}")
答案 1 :(得分:0)
你的意思是这样的吗?
public interface GitHubService {
@GET("users/{user}/repos")
Call<List<Repo>> listRepos(@Path("user") String user);
}
所有这些都在RetroFit简介http://square.github.io/retrofit/
中答案 2 :(得分:0)
尝试使用此
@GET("api/OneUser/{id}")
Call<AllUserDetails>GetAllUserDetails(@Path("id")String UserInfo);