【发布时间】:2020-09-11 04:54:57
【问题描述】:
我是 java 和 Android 的新手。 我正在尝试将一些变量传递给 Retrofit GET-Call。但对我来说没有任何效果,所以请你看看我的代码?
我必须更改什么来发送我的变量:
- myActuelFullName
- myOtherInfo
到服务器?
我的 java 文件:
public class Orte extends AppCompatActivity {
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_orte);
Intent myIntent = getIntent(); // gets the previously created intent
myActuelFullName = myIntent.getStringExtra("paramFullName"); // will return "paramFullName"
getEntries(myActuelFullName);
}
private void getEntries(String myActuelFullName) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://myDomain.de/api/")
.addConverterFactory(GsonConverterFactory.create())
.build();
JsonPlaceHolderApi jsonPlaceHolderApi = retrofit.create(JsonPlaceHolderApi.class);
String myOtherInfo = "testing123";
Call<List<Entries>> call = jsonPlaceHolderApi.getEntries();
Log.d("DEBUG", myActuelFullName ); // at this point the Variable is known!
call.enqueue(new Callback<List<Entries>>() {
@Override
public void onResponse(Call<List<Entries>> call, Response<List<Entries>> response) {
if (!response.isSuccessful()) {
//textViewResult.setText("Code: " + response.code());
return;
}
//
@Override
public void onFailure(Call<List<Entries>> call, Throwable t) {
// textViewResult.setText(t.getMessage());
}
});
还有我的 Placeholder-Api:
public interface JsonPlaceHolderApi {
@GET("get_entries.php")
Call<List<Entries>> getEntries();
@POST("http://myDomain.de/api/mypost.php/")
Call<Post> createPost(@Body Post post);
}
【问题讨论】:
标签: java android retrofit parameter-passing retrofit2