【发布时间】:2019-04-12 04:38:55
【问题描述】:
我正在尝试为每个客户的站点获取 CompanyEndpoint,但我对在界面上使用改造感到困惑。
这是我目前所拥有的:
CompanyName : "company1"
CompanyEndpoint : "https://example.com"
IdentityEndpoint : "https://example.com/identity"
AppLoginMode : "Anonymous"
AppRouterApi.java
public interface AppRouterApi {
@GET("api/sites/{CompanyName}")
Call<Company> getCompanyName (@Url String companyName);
}
公司.java
public class Company {
String Endpoint;
public String getEndpoint() {
return endpoint;
}
}
MainActivity.java
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://example.com/")
.addConverterFactory(GsonConverterFactory.create())
.build();
appRouterApi = retrofit.create(AppRouterApi.class);
getCompany();
}
private void getCompany(){
retrofit2.Call<Company> companyRequest = appRouterApi.getCompanyName(); //Error here saying a string cant be applied to ()
companyRequest.enqueue(new retrofit2.Callback<Company>() {
@Override
public void onResponse(retrofit2.Call<Company> call, retrofit2.Response<Company> response) {
if(!response.isSuccessful()){
textViewResult.setText("Code:" + response.code());
return;
}
Company company = response.body();
String content = "";
content += "Url" + company.getEndpoint();
textViewResult.setText(content);
}
@Override
public void onFailure(retrofit2.Call<Company> call, Throwable t) {
}
});
}
https://example/sites/{companyName}
所以如果我搜索: https://example/sites/company1
JSON 将有一个对象,我需要获取端点 URL 值,即:https://company1.com
编辑:我的 textViewReslt 返回 403
【问题讨论】:
标签: android json dynamic gson retrofit2